我编写了一个扩展方法:
public static IQueryable<TSource> ConditionalDefaultEmpty<TSource>(this IQueryable<TSource> source, bool condition)
{
return condition ? source.DefaultIfEmpty() : source ;
}然后我给这个方法打了个电话,就像这样:
var q = from sr in myDb.tblStudentsRegInfos
from de in myDb.tblDisciplinesEvents.Where(e => sr.Serial == e.tblStudentsRegInfoRef
&& e.tblStudentsRegInfoRef == studentRegId
&& (!forStudent || e.PublishOnInternet)
&& (!formDate.HasValue || e.RegDate >= formDate)
&& (!toDate.HasValue || e.RegDate <= toDate))
.ConditionalDefaultEmpty(noPrintAll)
join dt in myDb.tblDisciplinesTitles on de.tblDisciplinesTitlesRef equals dt.Serial
where sr.Serial == studentRegId
group sr by new
{
...
}
into std
select new
{....
};但我知道这个错误:
成员访问列名是不合法的..。
我怎样才能解决这个问题?
更新:我理解EF不能编译成IQueryable.
发布于 2014-12-06 12:53:00
您只是不能添加您的自定义扩展方法,并希望实体框架能够将其转换为SQL,尽管这将非常酷,至少在这种情况下是这样的。
也就是说,您可以将IQueryable转换为IEnumerable:
.AsEnumerable()
.ConditionalDefaultEmpty(noPrintAll)https://stackoverflow.com/questions/27331098
复制相似问题