我有一个查询:匿名托管DynamicMethods大会C#LINQ
_selectQuery = _selectQuery.Substring(0, _selectQuery.Length - 1) + ")";
var testData= (from student in view.StudentView
join school in db.Schools on student.schoolid equals school.id into schools
from sc in schools.DefaultIfEmpty()
join tr in db.Teacher on sc.id equals tr.schoolid into teacherSchools
from tsc in teacherSchools.DefaultIfEmpty()
select new
{
school, sc, tsc
}.Select(_selectQuery);
foreach (var item in testData)
{
allData.Add(item.ToDynamic());
}
上面的代码抛出异常在foreach /迭代部分:TESTDATA为空。
匿名在 Swift.PeopleCommon.Data.Export.EnhancedExportService.GetGridData(GridJsonGetRows 网格,布尔limitData)在 托管DynamicMethods大会lambda_method(封闭 ,<> f__AnonymousType337
13) at System.Linq.Enumerable.WhereSelectEnumerableIterator
2.MoveNext()
DynamicModule.ns.Wrapped_IEnhancedExportStore_a2d199ba35504f35a326f3807ad0f404 .__ 1(IMethodInvocation 输入,GetNextInterceptionBehaviorDelegate GetNext)的
我试过addung null checker like
join school in db.Schools on student==null ? 0 : student.schoolid equals school.id into something
但仍然抛出错误。
我试着创建一个类的选择部分(例如选择新的TestClass {}),而不是匿名,但仍然会引发异常。我可能会错过什么?
这应该是一个评论,而不是一个答案。 –
使用泛型助手扩展方法“IfNotNull”。看到这个链接http://stackoverflow.com/a/854619/1476708 – Hamix
我是否正确使用它? (g => g.id)等于tr.ifNotNull(g => g.schoolid)into teacherSchools 尽管如此,它仍会引发相同的错误。 – user742102