C#中检索,其中LINQ的条款 [英] C# retrieve where clause on linq
问题描述
有没有为了将来使用,或显示/打印建立一个LINQ查询的方式(更具体地说,在where子句)?
Is there a way to build a linq query in order to use it later or to display/print it (and more specifically, the where clause) ?
推荐答案
到底是什么你想要?您可以捕获只的表达式的从其中,
- 是这样的:
What exactly is it you want? You can capture just the expression from the Where
- something like:
Expression<Func<SomeType, bool>> predicate = row => row.IsActive
&& row.Color == "red";
由于这是要一个表达式树,有一个有意义的的ToString( )
。
Because this is going to an expression tree, there is a meaningful ToString()
.
如果您希望SQL(等等),那么这将是实现特定的。例如,使用LINQ到SQL,您可以使用 .LOG
- 例如, ctx.Log = Console.Out;
If you want the SQL (etc), then that will be implementation-specific. For example, with LINQ-to-SQL you can use .Log
- for example, ctx.Log = Console.Out;
如果你想谓词出中间的的IQueryable< T>
饲料,然后就是很多麻烦...
If you want the predicate out of the middle of an IQueryable<T>
feed, then that is much trickier...
这篇关于C#中检索,其中LINQ的条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!