Lambda Expression X

Asked

Viewed 495 times

2

Speaking in terms of overall performance (speed, integrity and etc...), using English expressions to query database, is better in the above terms or depends on?

2 answers

3


For the case of objects that implement IQueryable, there is the time of constructing the sentence that consumes some processing, therefore, starting from absolute terms, the sentence in static SQL will be or faster or equivalent to the generated SQL.

However, speaking of integrity and consistency, static SQL alone does not guarantee. All data mapping between programming language structures needs to be done manually by the programmer, which can produce common errors such as the lack of columns and/or information that can cause errors in the execution of a trivial system flow.

In the case of Entity Framework, when persisting data, the Framework performs some checks automatically, which improves consistency and referential integrity (does not guarantee 100%, but improves). If the code is generated from a database that already exists (Database First), Template objects will have to copy the database reliably. If the database is generated from the code (Code First), any validation placed as configuration will be replicated to the base.

Comparing one and the other, Expression Methods (alias lambda) and LINQ, there is no difference in performance, since both mount the object IQueryable in a very similar way. The difference is in the expressiveness of each. Expression Methods are more succinct, while LINQ is more didactic and clear by approaching a natural language, in this case English.

  • Okay, but in this case, as I asked, the comparison between Lynx and Lambda within what you said, has to say whether this is better than the one or both are equivalent in the performance context.

  • @pnet I updated for you.

0

  • Fábio, welcome to Stackoverflow! Thank you for wanting to help! However, your answer boils down to a link that is valid at the moment but nothing guarantees that it will continue to be so in the future. Stackoverflow should be viewed as a repository of knowledge and not just a question-answering site. In answering we must think not only of those who asked, but of all those who in the future will be able to benefit from our answer.

  • Just for the record, the example of this site is flawed, it never enumerates the values which makes both the lambda expression when the query Linq are never actually executed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.