Home > database >  When we use linq do we ever need to use from?
When we use linq do we ever need to use from?

Time:11-12

I like to use keyword where, for example.

I simply do it like this

Dim orderFromThisGridTrading = _orders1.Where(Function(x) x.customIdentifier = ASimpleGridTradeSettings.name).ToArray

However, most samples would say I have to use from

Dim customersForRegion = From cust In customers Where cust.Region = region

Which is weird af and don't follow normal vb.net format. That looks a like like SQL languages and not a real programming language.

I wonder if I can always avoid using Form and just use like I am using? Are there any cases where that is not possible?

Is this even a good idea?

CodePudding user response:

There is nothing bad in using query syntax in general. Especially in VB.NET it is very powerful and supports a lot of LINQ methods(more than in C#). Many prefer that because it can make your code more readable. But it seems that the opposite is true for you, you don't like it. Then use the method syntax, it supports all methods. I don't like it in VB.NET because of that ugly and verbose Function keyword, especially with GroupBy or Join i prefer query syntax.

I wonder if I can always avoid using From and just use like I am using? Are there any cases where that is not possible?

No, method syntax is always possible. Actually query syntax gets compiled to method syntax.

  • Related