C # retrieves where where on linq

Is there a way to create a linq query to use it later or to display / print it (and more specifically where clauses)?

+3
source share
5 answers

What exactly do you want? You can only capture an expression from Where- something like:

Expression<Func<SomeType, bool>> predicate = row => row.IsActive
          && row.Color == "red";

Since this happens with the expression tree, there is meaningful ToString().

If you want SQL (etc.) then this will be implementation specific. For example, with LINQ-to-SQL you can use .Log- for example,ctx.Log = Console.Out;

If you want the predicate to go out of the middle of the feed IQueryable<T>, it’s a lot more complicated ...

+9
source

LINQ.NET 3.5-?

http://msdn.microsoft.com/en-us/library/bb332048.aspx

- > LINQ .NET 3.5, 3.0, topicstarter.

edit2:

, TS # 3.0, .NET 3.5.

.

+1

You can look at System.Linq.Dynamic its add-on on linq to build dynamic, where, orderby, etc.

For example, tblProduct.Where ("product_id = @ 0", product_id)

This may be of some help.

0
source

Take a look at this example from MSDN:

// Lambda expression as executable code.
Func<int, bool> deleg = i => i < 5;
// Invoke the delegate and display the output.
Console.WriteLine("deleg(4) = {0}", deleg(4));

// Lambda expression as data in the form of an expression tree.
System.Linq.Expressions.Expression<Func<int, bool>> expr = i => i < 5;
// Compile the expression tree into executable code.
Func<int, bool> deleg2 = expr.Compile();
// Invoke the method and print the output.
Console.WriteLine("deleg2(4) = {0}", deleg2(4));
0
source

Linq cannot be displayed (AFAIK), if you mean the query 'linq2sql' (qg. Sql query built from linq), no, it cannot be printed.

-1
source

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


All Articles