在我的DAL中的RepositoryBase中,我有以下代码......我似乎无法弄清楚ObjectQuery query = ObjectSet; ?我接近了吗?
public IEnumerable<T> QueryObjectGraph(Expression<Func<T, bool>> filter, params string[] children)
{
//ObjectQuery<T> query = ObjectSet; //nope...requires 1 type argument
//ObjectQuery<T> query = ObjectSet<T>; //nope......type used like variable
// ObjectQuery<T> query = ObjectSet<T>(); //nope ...type used like variable
//ObjectQuery<T> query = new ObjectSet<T>(); //nope...no constructors defined
IQueryable<T> query;
foreach (var child in children)
{
query = query.Include(child);
}
return query.Where(filter);
}
答案 0 :(得分:3)
放松男人。不是故意听起来很粗鲁。你只是不知道自己在做什么。如果你看这里http://msdn.microsoft.com/en-us/library/dd412719.aspx,你会发现ObjectSet是ObjectQuery,所以赋值确实有效。但是你必须首先创建ObjectSet!
“因为我是专家”
看起来这个代码很有效
using (var ctx = new ModelContainer())
{
ObjectQuery<Person> objectQuery = ctx.People;
}
和ctx.People的类型是ObjectSet
您的代码中注释掉了什么是ObjectSet?在哪里创建?