tags:

views:

117

answers:

1

I have a linq query that i'd like to get the query syntax for.

var q = customers.Where(x => x.name == "smith");

Is there something like IQueryable.ToQuerySyntaxString()? that would return something like this:

from cust in customers where cust.name == "smith";

I'm asking because I can construct my query using method syntax, but would like to see the query syntax equivalent to help me learn how to write in the alternate form.

+1  A: 

It actually works the other way around. When you use the second syntax (from x in y where w), it actually gets compiled into the first (y.Where(x => w)).

I'm sure you could write something to produce the second version using Expression Trees, but I'm not aware of anything in the framework that will do it automatically for you.

Aaronaught
Not the anwser I was hoping for. Oh well.
Jacob