解决方案 »

  1.   

    参见:http://kb.cnblogs.com/page/42489/
      

  2.   


    这个实现比较复杂,效率可能不高,文中介绍的是WHERE一字段,那如果多个字段又该如何操作呢?有没有简单而高效的方法,在查询字段与查询内容不明确的情况下,实现LINQ动态查询是否可行?
    若在知道查询字段的情况下,我是知道如何做,可以用别人封装好的一个类:PredicateExtensions
      

  3.   


    首先,查询是可以“自身跟自身”组合的。毕竟是延迟执行的,而Linq to SQL 和 SQL Server 系统都会分别对查询先进性几十种可能性的分析,最后只取最优化的查询计划去执行。不过最重要地是,你为啥不同时使用 ADO.NET 呢?为什么刚学会用两天什么 Linq to SQL 就不用了 ADO.NET 了呢?真是没有长性啊,学什么都是半途而废。跟那种抱着ADO.NET 不敢去尝试 LINQ Provider的人有什么两样呢?
      

  4.   

    google dynamic linq
    使用这个库,可以把查询写成类似sql那样的字符串,以及得到dynamic结果的查询。
      

  5.   


    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();
    }
      

  6.   

    有库的System.Linq.DynamicProject Description
    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/