performance - What should you use for joining in LINQ, Query syntax or method syntax? -


i know in terms of performance there difference between using query syntax or method syntax (lambda expressions) joining 2 entities?

i know in general there no difference in terms of result, between query syntax , method syntax. however, joining of these better use performance wise? here sample code:

var queryresult = (from p in people                        join in incomes       on p.personid equals i.personid                        select new { p.personid, p.name, p.age, i.amount }                       ).tolist();          var lambdaresult = people.join(incomes,                       p => p.personid,                       => i.personid,                      (p, i) => new { p.personid, p.name, p.age, i.amount }).tolist(); 

i have went through these websites nothing has been mentioned join https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/query-syntax-and-method-syntax-in-linq

linq - query syntax vs method chains & lambda

there no difference. first version (query language) translated lexically second 1 (method syntax) before "real" compilation. query language syntactic sugar , transformed method calls. these calls compiled (if possible - translation not care correctness of result, e.g. if people.join valid c# , there such join method in whatever people might be).

there maybe difference in translation uses explicit select call instead of resultselector parameter of join method, not measurably impact performance.

this article jon skeet helped me understand transformation query language method syntax.


to answer question "what should use": you. consider:

  • what more readable/understandable (and co-workers!)
  • complex queries more readable in query syntax, sql-like style can easier read long chain of method calls
  • note every query syntax expression can expressed method calls, not method calls can expressed in query syntax
  • mixing both syntaxes in single query more confusing sticking 1 of them

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -