首页 新闻 会员 周边

求Linq 用户自定义动态组合查询 方案

0
悬赏园豆:60 [已解决问题] 解决于 2014-03-10 16:20

用户自己根据选择字段  表达式 (>  =  <等) 进行查询   如 

.L的主页 .L | 菜鸟二级 | 园豆:205
提问于:2013-09-09 09:06
< >
分享
最佳答案
0

参考地址:http://www.cnblogs.com/cxd4321/archive/2009/09/29/1576202.html

http://www.cnblogs.com/bitstudio/archive/2009/03/04/1402652.html

 

我个人使用:PredicateBuilder.cs这个类,来实现动态Linq。如果用在EF中,需要搭配LinqKit来使用。

收获园豆:20
幻天芒 | 高人七级 |园豆:37175 | 2013-09-09 10:00

这些都是旧方法了,新方法已经内置有支持了。。

var productsWithPriceGreaterThan100 = ctx.Products.Where("Price > 100").ToList();

var productsWithPriceLowerThan100 = ctx.Products.Where("Price < @0", 100).ToList();

var productNames = ctx.Products.Select(x => x.Name).Where("@it != @0", "Some Name").ToList();

 

Make sure you have references to both System.Web and System.Web.Extensions, this is required, and won’t affect anything.

 

参考资料:http://weblogs.asp.net/ricardoperes/archive/2013/06/13/dynamic-linq-extension-method.aspx

孑孓子 | 园豆:226 (菜鸟二级) | 2013-09-09 10:15

@厦门蚊孑: 学习了,看来out了~

幻天芒 | 园豆:37175 (高人七级) | 2013-09-09 10:28
其他回答(4)
0

微软有个示例项目,你自己查一下:DynamicQueryable

收获园豆:10
Launcher | 园豆:45045 (高人七级) | 2013-09-09 09:19
0

看看这篇博文:http://weblogs.asp.net/ricardoperes/archive/2013/06/13/dynamic-linq-extension-method.aspx

var productsWithPriceGreaterThan100 = ctx.Products.Where("Price > 100").ToList();

var productsWithPriceLowerThan100 = ctx.Products.Where("Price < @0", 100).ToList();

var productNames = ctx.Products.Select(x => x.Name).Where("@it != @0", "Some Name").ToList();

 

Make sure you have references to both System.Web and System.Web.Extensions, this is required, and won’t affect anything.

收获园豆:10
孑孓子 | 园豆:226 (菜鸟二级) | 2013-09-09 10:17
0

http://esql.codeplex.com

收获园豆:10
麦舒 | 园豆:452 (菜鸟二级) | 2013-09-10 00:43
0

System.Linq.Dynamic

收获园豆:10
sheng00 | 园豆:324 (菜鸟二级) | 2013-09-10 15:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册