質問
linqクエリを作成して後で使用したり、表示(またはより具体的にはwhere句)したりするためにクエリを作成する方法はありますか?
解決
あなたが望むものは何ですか? Where
から expression のみをキャプチャできます。次のようなものです。
Expression<Func<SomeType, bool>> predicate = row => row.IsActive
&& row.Color == "red";
これは式ツリーに送られるため、意味のあるToString()
があります。
SQL(など)が必要な場合は、実装固有になります。たとえば、LINQ-to-SQLでは.Log
を使用できます。たとえば、ctx.Log = Console.Out;
IQueryable<T>
フィードの途中から述部が必要な場合は、はるかに複雑です...
他のヒント
LINQは.NET 3.5機能ではありませんか?
編集:
http://msdn.microsoft.com/en-us/library /bb332048.aspx
-<!> gt; LINQは.NET 3.5からのみ利用可能であり、topicstarterが要求する3.0ではありません。
edit2:
OK、TSは.NET 3.5に付属するC#3.0について話します。
かなり紛らわしい。
System.Linq.Dynamicを見て、linqのアドオンを使用して、動的where、orderbyなどを構築できます
eg tblProduct.Where(<!> quot; product_id = @ 0 <!> quot ;, product_id)
それは何らかの助けになるかもしれません。
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));
Linqは表示できません(AFAIK)。「linq2sql」クエリ(qg。linqから構築されたsqlクエリ)を意味する場合、いいえ、印刷できません。