如何动态构建LINQ [英] How do I build up LINQ dynamically
问题描述
我正在尝试确定是否可以使用动态(字符串)where子句构建LINQ查询?
我注意到Predicate.OR Preditcate.AND的东西,但这不是我在说的。
任何建议?
如果您在谈论字符串 其中
子句(而不是自己构建表达式) - 然后动态LINQ库(在3.5样本中,IIRC)应该足够了。
请注意,以下示例用于数据库使用;但是您可以通过在内存数据中调用 .AsQueryable()
将其与LINQ对象一起使用。
alt text http://www.scottgu.com/blogposts/dynquery/step2.png
I have a scenario where I have custom configured column names, associated operators like < > = between etc. and then a value associated.
I'm trying to determine if it is possible to build up a LINQ query with a dynamic (string) where clause?
I've noticed the Predicate.OR Preditcate.AND stuff, but that is not quite what I'm talking about.
Any suggestions?
If you are talking about a string Where
clause (rather than building the expression etc yourself) - then the Dynamic LINQ Library (in the 3.5 samples, IIRC) should suffice.
Note that the example below is for database usage; but you can use it with LINQ-to-Objects by calling .AsQueryable()
on your in-memory data.
alt text http://www.scottgu.com/blogposts/dynquery/step2.png
这篇关于如何动态构建LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!