我在RosterSummaryData_Subject_Local实体上执行linq查询时收到错误。我似乎无法弄清楚出了什么问题或解决方案。
无法创建类型为“System.Int32 []”的null常量值。只要 支持实体类型,枚举类型或基元类型 这个背景。
我的代码第一个实体上下文的LINQ查询:
var subjLocal = customerContext.RosterSummaryData_Subject_Local.Where(s =>
(s.fkRosterSetID == 0) &&
(statsInfo.TestInstanceIDsList.Contains(s.fkTestInstanceID)) &&
(s.fkTestTypeID == statsInfo.TestTypeID) &&
(statsInfo.SchoolYearIDsList.Contains(s.fkSchoolYearID)) &&
(s.fkRosterTypeID == 1) &&
(s.fkSchoolID == 0) &&
(s.fkDepartmentID == 1) &&
(s.fkCourseID == 1) &&
(s.fkPeriodID == 1) &&
(statsInfo.DemoCatIDsList.Contains(s.fkDemoCommonCategoryID)) &&
(statsInfo.DemoCodeIDsList.Contains(s.fkDemoCommonCodeID)) &&
(statsInfo.TestSubjectIDsList.Contains(s.fkTest_SubjectID)));
答案 0 :(得分:1)
听起来您的Int32[]
类型之一是null
。在访问.Contains
方法之前,请尝试添加检查:
var subjLocal = customerContext.RosterSummaryData_Subject_Local.Where(s =>
(s.fkRosterSetID == 0) &&
(statsInfo.TestInstanceIDsList != null &&
statsInfo.TestInstanceIDsList.Contains(s.fkTestInstanceID)) &&
(s.fkTestTypeID == statsInfo.TestTypeID) &&
(statsInfo.SchoolYearIDsList != null &&
statsInfo.SchoolYearIDsList.Contains(s.fkSchoolYearID)) &&
(s.fkRosterTypeID == 1) &&
(s.fkSchoolID == 0) &&
(s.fkDepartmentID == 1) &&
(s.fkCourseID == 1) &&
(s.fkPeriodID == 1) &&
(statsInfo.DemoCatIDsList != null &&
statsInfo.DemoCatIDsList.Contains(s.fkDemoCommonCategoryID)) &&
(statsInfo.DemoCodeIDsList != null &&
statsInfo.DemoCodeIDsList.Contains(s.fkDemoCommonCodeID)) &&
(statsInfo.TestSubjectIDsList != null &&
statsInfo.TestSubjectIDsList.Contains(s.fkTest_SubjectID)));
或者,如果它们为空是好的(我认为它不是,但以防万一),您可以更改上述检查以遵循这种模式:
(statsInfo.DemoCatIDsList == null ||
statsInfo.DemoCatIDsList.Contains(s.fkDemoCommonCategoryID)) &&