Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LINQ to Entities

LINQ to Entities

Scheduled Pinned Locked Moved C#
csharpdatabaselinqperformancequestion
22 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pete OHanlon

    Tamimi - Code wrote:

    why i need to learn new syntax to get lower performance ?

    Who says the performance is lower? A well designed entity query can be as performant as a hand designed SQL query. You don't need to use the new syntax - it's entirely up to you. Linq2Entities does not replace ADO.NET; it's just another tool in your arsenal. Use it, or not; that's entirely up to you.

    I'm not a stalker, I just know things. Oh by the way, you're out of milk.

    Forgive your enemies - it messes with their heads

    My blog | My articles | MoXAML PowerToys | Onyx

    T Offline
    T Offline
    Tamimi Code
    wrote on last edited by
    #3

    while its not replacing anything and have no performance benefits, why its exist ? i am asking this because the lambda expression is hard :rolleyes: thank you

    P P 2 Replies Last reply
    0
    • T Tamimi Code

      do you really use it ? why i need to learn new syntax to get lower performance ? when i have no time and the high performance is not a must i go for the Dataset. its ok with the collections and arrays but with the database !! what do you think ? regardless that i am late to ask this :D

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #4

      I like LINQ, it can save a lot of time. Especially if you are using LINQ to SQL. But I really like the simple things such as counting specific values in a list...

      int count = list.Count(c => c.Value > 10);

      much nicer and quicker than...

      int count = 0;
      foreach(CustomClass c in list)
      {
      if(c.Value > 10)
      count++;
      }

      Illogical thoughts make me ill

      P 1 Reply Last reply
      0
      • M musefan

        I like LINQ, it can save a lot of time. Especially if you are using LINQ to SQL. But I really like the simple things such as counting specific values in a list...

        int count = list.Count(c => c.Value > 10);

        much nicer and quicker than...

        int count = 0;
        foreach(CustomClass c in list)
        {
        if(c.Value > 10)
        count++;
        }

        Illogical thoughts make me ill

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #5

        And what do you think it's doing in the background?

        musefan wrote:

        it can save a lot of time

        Coding time, yes. Maybe not execution time (have you benchmarked it?). Maybe not maintenance time if the next person to touch the code doesn't understand it. I'll stick with simpler code.

        M R N 3 Replies Last reply
        0
        • T Tamimi Code

          while its not replacing anything and have no performance benefits, why its exist ? i am asking this because the lambda expression is hard :rolleyes: thank you

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #6

          It's for lazy people who don't want to type much and want to exhibit their cutting-edge skillz. :-D

          1 Reply Last reply
          0
          • T Tamimi Code

            do you really use it ? why i need to learn new syntax to get lower performance ? when i have no time and the high performance is not a must i go for the Dataset. its ok with the collections and arrays but with the database !! what do you think ? regardless that i am late to ask this :D

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #7

            Tamimi - Code wrote:

            when i have no time and the high performance is not a must i go for the Dataset

            That's no reason to use a DataSet... in fact there pretty much is no reason to use a DataSet. "If you don't have time to do it right, when will you have time to do it over?"

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              And what do you think it's doing in the background?

              musefan wrote:

              it can save a lot of time

              Coding time, yes. Maybe not execution time (have you benchmarked it?). Maybe not maintenance time if the next person to touch the code doesn't understand it. I'll stick with simpler code.

              M Offline
              M Offline
              musefan
              wrote on last edited by
              #8

              Yes, I did mean quicker to code and I understand that it will be doing a similar if not identical thing in the background. I did just do a test and the foreach loop is around 3 times quicker than the LINQ query (in this case), but for general use I think the faster development time is worth it, and it is better maintenance - if the next person didn't understand then it would become time for them to learn ;) Anyway, if performance became important then there would be a lot more general style coding stripped away I am sure.

              Illogical thoughts make me ill

              1 Reply Last reply
              0
              • T Tamimi Code

                while its not replacing anything and have no performance benefits, why its exist ? i am asking this because the lambda expression is hard :rolleyes: thank you

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #9

                It exists to bring database functionality into the realm of coders who may have limited SQL skills, by integrating query capabilities into a language they are comfortable with.

                Tamimi - Code wrote:

                i am asking this because the lambda expression is hard

                That's just being lazy. Lambda expressions are not just for L2E, so you really should learn them.

                I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  Tamimi - Code wrote:

                  when i have no time and the high performance is not a must i go for the Dataset

                  That's no reason to use a DataSet... in fact there pretty much is no reason to use a DataSet. "If you don't have time to do it right, when will you have time to do it over?"

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #10

                  PIEBALDconsult wrote:

                  If you don't have time to do it right, when will you have time to do it over?"

                  yes, hopefully; maybe just enough to do it differently and wrong again. :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  P 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    PIEBALDconsult wrote:

                    If you don't have time to do it right, when will you have time to do it over?"

                    yes, hopefully; maybe just enough to do it differently and wrong again. :)

                    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #11

                    Until you've fully explored enough of the wrong ways, you'll never truly appreciate the right way. :-D

                    P 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Until you've fully explored enough of the wrong ways, you'll never truly appreciate the right way. :-D

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #12

                      You missed the word "grasshopper" from the end of that sentence.

                      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                      Forgive your enemies - it messes with their heads

                      My blog | My articles | MoXAML PowerToys | Onyx

                      1 Reply Last reply
                      0
                      • P PIEBALDconsult

                        And what do you think it's doing in the background?

                        musefan wrote:

                        it can save a lot of time

                        Coding time, yes. Maybe not execution time (have you benchmarked it?). Maybe not maintenance time if the next person to touch the code doesn't understand it. I'll stick with simpler code.

                        R Offline
                        R Offline
                        Rob Philpott
                        wrote on last edited by
                        #13

                        Good point. LINQ is usually slower when I've dabbled with it. And although more verbose I always prefer simple explicit code, less error prone, easier for others to understand and easier to debug.

                        Regards, Rob Philpott.

                        1 Reply Last reply
                        0
                        • T Tamimi Code

                          do you really use it ? why i need to learn new syntax to get lower performance ? when i have no time and the high performance is not a must i go for the Dataset. its ok with the collections and arrays but with the database !! what do you think ? regardless that i am late to ask this :D

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #14

                          I'm only just starting to learn LINQ: I have pretty reasonable SQL abilities already. The main reason I am learning it is that I feel that the stronger typing and compile time syntax checking available in LINQ to SQL has got to produce better, cleaner, more reliable solutions than hand crafted SQL. Once I've got a good feeling for it, I'll make the decision to either go with it or back - but until I have that level of confidence in my abilities with it, I can't make that call. If I don't learn LINQ, I made that call without sufficient information.

                          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          P 1 Reply Last reply
                          0
                          • T Tamimi Code

                            do you really use it ? why i need to learn new syntax to get lower performance ? when i have no time and the high performance is not a must i go for the Dataset. its ok with the collections and arrays but with the database !! what do you think ? regardless that i am late to ask this :D

                            N Offline
                            N Offline
                            Not Active
                            wrote on last edited by
                            #15

                            Perhaps you could look here for some information Entity Framework Performance[^]


                            I know the language. I've read a book. - _Madmatt

                            1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              And what do you think it's doing in the background?

                              musefan wrote:

                              it can save a lot of time

                              Coding time, yes. Maybe not execution time (have you benchmarked it?). Maybe not maintenance time if the next person to touch the code doesn't understand it. I'll stick with simpler code.

                              N Offline
                              N Offline
                              Not Active
                              wrote on last edited by
                              #16

                              PIEBALDconsult wrote:

                              have you benchmarked it?

                              Yes, I have. Entity Framework Performance[^]


                              I know the language. I've read a book. - _Madmatt

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I'm only just starting to learn LINQ: I have pretty reasonable SQL abilities already. The main reason I am learning it is that I feel that the stronger typing and compile time syntax checking available in LINQ to SQL has got to produce better, cleaner, more reliable solutions than hand crafted SQL. Once I've got a good feeling for it, I'll make the decision to either go with it or back - but until I have that level of confidence in my abilities with it, I can't make that call. If I don't learn LINQ, I made that call without sufficient information.

                                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #17

                                OriginalGriff wrote:

                                If I don't learn LINQ, I made that call without sufficient information.

                                Hear hear! I finally dabbled in a little bit of Linq (to SQL?) a few weeks ago. It gave me no benefit and I don't see how it can deliver any. Especially considering I use several different database systems, not just Sql Server.

                                OriginalGriff wrote:

                                LINQ to SQL has got to produce better, cleaner, more reliable solutions than hand crafted SQL.

                                Not if you've been hand crafting clean reliable SQL for twenty years. If Linq produces better SQL than you do, then go with it.

                                OriginalGriffO 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  OriginalGriff wrote:

                                  If I don't learn LINQ, I made that call without sufficient information.

                                  Hear hear! I finally dabbled in a little bit of Linq (to SQL?) a few weeks ago. It gave me no benefit and I don't see how it can deliver any. Especially considering I use several different database systems, not just Sql Server.

                                  OriginalGriff wrote:

                                  LINQ to SQL has got to produce better, cleaner, more reliable solutions than hand crafted SQL.

                                  Not if you've been hand crafting clean reliable SQL for twenty years. If Linq produces better SQL than you do, then go with it.

                                  OriginalGriffO Offline
                                  OriginalGriffO Offline
                                  OriginalGriff
                                  wrote on last edited by
                                  #18

                                  PIEBALDconsult wrote:

                                  Not if you've been hand crafting clean reliable SQL for twenty years.

                                  Not quite what I meant: I was thinking more that finger trouble with LINQ is more likely to cause a compilation error, where in SQL it is run time and so harder to test and detect.

                                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                  P 1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    PIEBALDconsult wrote:

                                    Not if you've been hand crafting clean reliable SQL for twenty years.

                                    Not quite what I meant: I was thinking more that finger trouble with LINQ is more likely to cause a compilation error, where in SQL it is run time and so harder to test and detect.

                                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                    P Offline
                                    P Offline
                                    PIEBALDconsult
                                    wrote on last edited by
                                    #19

                                    Oh, sure, but you can develop and test your more-complex SQL statements with another tool and then copy-and-paste them into your application. An additional benefit of that is that it drives parameter use rather than concatenation.

                                    OriginalGriffO 1 Reply Last reply
                                    0
                                    • P PIEBALDconsult

                                      Oh, sure, but you can develop and test your more-complex SQL statements with another tool and then copy-and-paste them into your application. An additional benefit of that is that it drives parameter use rather than concatenation.

                                      OriginalGriffO Offline
                                      OriginalGriffO Offline
                                      OriginalGriff
                                      wrote on last edited by
                                      #20

                                      I would assume that Linq generates parametrized queries anyway: I always use them with SQL. :-D

                                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                      P 1 Reply Last reply
                                      0
                                      • OriginalGriffO OriginalGriff

                                        I would assume that Linq generates parametrized queries anyway: I always use them with SQL. :-D

                                        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                        P Offline
                                        P Offline
                                        PIEBALDconsult
                                        wrote on last edited by
                                        #21

                                        OriginalGriff wrote:

                                        I always use them with SQL

                                        Yes, but others don't, because concatenation is easier unless your framework (e.g. Linq) makes parameters easier.

                                        OriginalGriffO 1 Reply Last reply
                                        0
                                        • P PIEBALDconsult

                                          OriginalGriff wrote:

                                          I always use them with SQL

                                          Yes, but others don't, because concatenation is easier unless your framework (e.g. Linq) makes parameters easier.

                                          OriginalGriffO Offline
                                          OriginalGriffO Offline
                                          OriginalGriff
                                          wrote on last edited by
                                          #22

                                          PIEBALDconsult wrote:

                                          Yes, but others don't, because concatenation is easier they are lazy idiots who like leaving their DB wide open to an SQL injection attack

                                          FTFY! :laugh:

                                          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups