【发布时间】:2011-01-24 16:00:31
【问题描述】:
我有一个存储库类,它有一个返回 ObjectSet 的方法
类似
public class Repository:ObjectContext
{
public IObjectSet<T> GetObjectSet()
{...}
}
当我在查询中使用它时,我得到 linq to entity 错误(不识别方法...)
我喜欢这样的想法,即拥有一个不会每次都重新生成的通用存储库(使用 T4 模板) 有没有办法扩展查询提供程序以识别我的方法?但我确实想在服务器上解决它(换句话说,参与查询生成)。 使用它的示例代码是:
static readonly Func<Repository,
string, AuthorizedUser> getInstitutionByAuthorizedUserName = CompiledQuery.Compile(
(ObjectContext ctx, string userName) =>
(from inst in ctx.GetObjectSet<Institution>()
join auths in ctx.GetObjectSet<AuthorizedUser>()
on inst.Key equals auths.Institution.Key
where auths.Name == userName
select inst.Key).SingleOrDefault();
【问题讨论】:
-
您没有显示尝试使用它的代码,这使得弄清楚发生了什么变得更加困难......
-
不识别哪种方法?
-
它不识别 ctx.GetObjectSet
() 方法
标签: c# entity-framework linq-to-entities