1
我写了一个扩展方法:扩展方法对于IQueryable的工作不
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 ...
请问,当你不使用你的方法查询工作? – Euphoric 2014-12-06 13:03:22
是的,它的工作非常好。 – 2014-12-06 13:03:50
你可以执行第二个(你的方法的部分)作为单独的查询吗? – Euphoric 2014-12-06 13:04:32