考虑这个编译的 linq-to-sql 查询:
private static Func<LINQDBDataContext, string, IQueryable<Pet>>
QueryFindByName =
CompiledQuery.Compile((
MyLinqDataContext context, string name) =>
from p in context.Pets where p.Name == name select p);
但是我已经在类中持有对上下文的私有引用,我希望能够在不暴露上下文的情况下将查询标记为公共,例如
private static MyLinqDataContext context = SomeUtilityClass.GetMeMyContext();
//...
public static Func<string, IQueryable<Pet>> QueryFindByName =
CompiledQuery.Compile((string name) =>
from p in this.context.Pets where p.Name == name select p);
//doesn't compile as expects TArg0 to be a DataContext.
有没有办法在不为每个查询创建公共包装函数的情况下做到这一点?