我想将其转换为通用类型:
using System.Linq.Expression
using System.Collections.Generic
public IQueryable<T> AllIncluding(
params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = All;
foreach (var includeProperty in includeProperties)
{
// query = query.Include(includeProperty);
}
return query;
}
但它似乎不起作用,我该怎么做?
答案 0 :(得分:2)
Include
方法仅在DbQuery<T>
上可用,因此您必须使用直接强制转换或as
操作数或使用方法DbExtensions.Include将查询强制转换为该方法:
public IQueryable<T> AllIncluding(
params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = All as DbQuery<T>;
if (query == null)
{
return All;
}
foreach (var includeProperty in includeProperties)
{
// query = query.Include(includeProperty);
}
return query;
}
答案 1 :(得分:1)
为System.Data.Entity
添加使用;
实体框架4.1包含强类型版Include
:http://msdn.microsoft.com/en-us/library/gg671236(VS.103).aspx
这是一种扩展方法。