LINQ query expression versus fluent (dot) notation [duplicate]
Dim namePriceQuery = From prod In products
Select prod.Name, prod.Price
OR
Dim namePriceQuery = products.select(function(x) New With{ Key .newName =x.name _
, Key .newPrice= x.price})
To my knowledge the only difference is with with the second expression has the benefits of the Key keyword. What exactly is the difference between the two?? And what scenarios would I choose to use one or the other in? What are the pros and cons of one vs the other?
I am assuming the C# syntax equivalent will work the same and should be used in similar before mention scenarios. Thank you very much!
Either one works the same but I would choose the one that is most readable.
Both statements are equal. Linq queries formulated with linq syntax are translated into the appropriate method calls.
Select what fits you best in terms of readability and/or makes your code more understandable. If you get really complex queries, using select many and grouping the linq syntax is much better to read.
I switch between both forms of linq queries depending on the situation.
精彩评论