开发者

LINQ query expression versus fluent (dot) notation [duplicate]

This question already has answers here: Fluent and Query Expression — Is there any benefit(s) of one over other? (14 answers) 开发者_Python百科 Closed 2 years ago.
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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜