参考地址: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来使用。
这些都是旧方法了,新方法已经内置有支持了。。
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
@厦门蚊孑: 学习了,看来out了~
微软有个示例项目,你自己查一下:DynamicQueryable
看看这篇博文: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.
http://esql.codeplex.com
System.Linq.Dynamic