匿名托管动态方法程序集c# linq

本文关键字:程序集 linq 方法 动态 | 更新日期: 2023-09-27 18:17:56

我有一个查询:

_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/iteration部分抛出异常:testData为null。

匿名托管的动态方法程序集在lambda_method(闭包, <>f__AnonymousType337 13 ) at System.Linq.Enumerable.WhereSelectEnumerableIterator . movenext ()
在Swift.PeopleCommon.Data.Export.EnhancedExportService.GetGridData (GridJsonGetRows网格,布尔值limitData)DynamicModule.ns.Wrapped_IEnhancedExportStore_a2d199ba35504f35a326f3807ad0f404.__1 (IMethodInvocationGetNextInterceptionBehaviorDelegate getNext)

我尝试添加null检查器,如

 join  school in db.Schools on student==null ? 0 : student.schoolid equals school.id into something

但仍抛出错误。

我试着为选择部分创建一个类(例如。选择新的TestClass{})而不是匿名,但仍然抛出异常。我还能错过什么呢?

匿名托管动态方法程序集c# linq

检查from tsc in teacherSchools.DefaultIfEmpty()中的tsc是否为NULL。

编辑1:

我认为异常是在

中抛出的。
select new { school, sc, tsc }

检查内部对象

select new 
{ 
   School= (school==null ? new School() : school),
   etc
}

我也得到了同样的错误。原因是,其中一个db字段被设置为默认值,但db列的值为NULL。所以我用默认字段更新了这个字段这很好