我正在尝试使用 Entity SQL 编写一个已编译的查询,但我在ToList()
网上遇到了这个错误:
LINQ to Entities 无法识别方法 'System.Data.Objects.ObjectQuery`1[BLL.Company] OrderBy(System.String, System.Data.Objects.ObjectParameter[])' 方法,并且该方法无法转换为存储表达式。
这是我正在尝试的代码:
class param
{
public string where, orderby;
public int skip, take;
}
..
public class BLL.CompanyManager
{
private static readonly Func<DbContext, param, IQueryable<CompanyInfo>> companyList;
static MyClass()
{
companyList = CompiledQuery.Compile<DbContext, param, IQueryable<CompanyInfo>>(
(DbContext db, param p) =>
db.Companies.Include("Projects")
//.Where(p.where)
.OrderBy(p.orderby)
.Skip(p.skip)
.Take(p.take)
.Select(row => new CompanyInfo()
{
...
})
);
public static List<CompanyInfo> CompanyList(..)
{
...
List<CompanyInfo> list = new List<CompanyInfo>();
using (var db = (DbContext.Instance())
{
list.AddRange(companyList(db, params).ToList<CompanyInfo>()); // <== ERROR
}
return list;
}
}
}