解决方案 »
- 为什么查新到第300条就得不到数据了呢?怎么解决
- 用random类随机生成一个二维数组,大家看这样写对吗?
- 问个高难问题,谁知道如何用C#关闭和打开显卡硬件加速?
- 如何实现URL重写.........在线等....
- 打开文件时出现:在web窗体设计器中未能加载该文件,请更改下列错误,然后尝试重新加载
- 求助:WMP控件上面呢叠加透明Label标签的问题
- 有谁教教怎样用castle.net 提供的vs工具ActiveWriter
- 求思路,源码,资料。关于邮件群发
- 怎么让datagrid自动创建列的时候生成超级链接列??
- C# Window Form中如何作圆形的按钮,并且鼠标放上去后有动画效果
- VS2012无法安装程序包哪位大牛帮忙解决一下
- [求助]C#使用RSA加密,只有一个公钥,要加密后的密文长度要256bit,如何实现?
这个实现比较复杂,效率可能不高,文中介绍的是WHERE一字段,那如果多个字段又该如何操作呢?有没有简单而高效的方法,在查询字段与查询内容不明确的情况下,实现LINQ动态查询是否可行?
若在知道查询字段的情况下,我是知道如何做,可以用别人封装好的一个类:PredicateExtensions
首先,查询是可以“自身跟自身”组合的。毕竟是延迟执行的,而Linq to SQL 和 SQL Server 系统都会分别对查询先进性几十种可能性的分析,最后只取最优化的查询计划去执行。不过最重要地是,你为啥不同时使用 ADO.NET 呢?为什么刚学会用两天什么 Linq to SQL 就不用了 ADO.NET 了呢?真是没有长性啊,学什么都是半途而废。跟那种抱着ADO.NET 不敢去尝试 LINQ Provider的人有什么两样呢?
使用这个库,可以把查询写成类似sql那样的字符串,以及得到dynamic结果的查询。
public Person[] QueryPersons(string name, int? gender)
{
MyDataContext dc = new MyDataContext();
IQueryable<Person> q = dc.Persons; if (!String.IsNullOrEmpty(name))
q = q.Where(person => person.Name.Contains(name)); if (gender.HasValue)
q = q.Where(person => person.Gender = gender); return q.OrderBy(person => person.Name).ToArray();
}
Extends System.Linq.Dynamic to support Execution of Lambda expressions defined in a string against Entity Framework or any provider that supports IQueryable.I originally came across this source code on Scott Guthrie's Blog while searching for a mechanism to execute dynamic linq statements against entity framework. While this code partially fulfilled my need both it and the assembly System.Linq.Dynamic.dll available for download from NuGet lacked the exact functionality I required. Specifically it did not allow me to execute a full lambda expression represented as a string against my entity objects. In addition it lacked support for Take and Union as well as many other extension functions, though these were the only two with which I was interested. As a consequence I extended the code to support these features. I thought my efforts might benefit someone else so I have decided to host it on codeplex. The original code is licensed under Ms-PL and in accordance with this license the derived codebase I have created is licensed similarly.http://dynamiclinq.codeplex.com/