views:

38

answers:

2

Just starting getting into Entity Framework and Linq for EF. I'm not sure which of the two query methods I should concentrate on, method-based or query-based?

Is there an obvious choice as to which one is easier to use, for both simple and more complex queries, hence should be the one I concentrate on? Assuming I'm using VS2010 does method based have an advantage in terms of having more design time checks/prompts from the IDE to make it easier to get things right prior to running the application?

thanks

+2  A: 

The method syntax is more complete; there will be things you can't do with the query syntax without plugging in a method here or there inline. Also, for some very simply queries, the method syntax can seem more concise, IMO.

On the other hand, the query syntax can appear to describe a query more naturally to someone familiar with SQL.

I always figured I would use the Method syntax exclusively when I started learning Linq in general. But I do find myself pounding out query syntax queries sort of automatically at times, too. Perhaps you could concentrate on the Method syntax due to the completeness and the familiarity factor (if those are at all valuable to you), and maybe you'll find that the query syntax just sort of 'comes to you' as you go, too.

Andrew Barber
+1  A: 

I Personally like the Method-Based syntax better, although Query Expression syntax is more readable and in the case of complicated queries, easier to write, But it's yet another level of abstraction and I think if we make ourselves familiar with the Method Based syntax, we can always turn it into Query Expression syntax but necessarily not the other way around, but that's just my opinion.

Morteza Manavi