Get query syntax for LINQ query

I have a linq query that I would like to get the query syntax.

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

Is there something like IQueryable.ToQuerySyntaxString ()? which will return something like this:

from cust in clients, where cust.name == "blacksmith";

I ask because I can build my query using the method syntax, but I would like the query syntax to be equivalent to help me learn how to write in alternative form.

+3
source share
3 answers

In fact, it works the other way around. When you use the second syntax ( from x in y where w), it will actually compile into the first ( y.Where(x => w)).

, -, , Expression Trees, , .

+1

re-linq relinq.codeplex.com

new QueryParser ().GetParsedQuery (q.Expression).ToString()

.

0

Resharper will often let you do this. It can offer conversion from for / foreach to LINQ, as well as LINQ back to loops (see http://www.jetbrains.com/resharper/whatsnew/whatsnew_60.html#LINQtoLoops for the latter), as well as a chain of LINQ methods to / from query syntax.

0
source

Source: https://habr.com/ru/post/1728215/


All Articles