这似乎是在编译以下linq查询时出现的错误。我已经阅读了一些类似的问题,但都强调使用.Any()函数而不是.Contains()..然而,尽管如此,编译语句似乎有错误,并记录了异常。
这是声明: -
int result=0;
result = (from u in objContext.CLG_challengeMaster
where u.appId == applicationId
&& objContext.CLG_taskDetail.Any(e => e.challengeId == u.id)
&& !objContext.CLG_challengeDetail.Any(e => e.challengeId == u.id && (e.userId == null && e.groupId == null && e.appGroupId == null && e.roleId == null))
select u).Count();
这是错误日志:
Message: System.NotSupportedException: Unable to create a constant value of type 'DataAccess.Entities.Models.CLG_taskDetail'. Only primitive types or enumeration types are supported in this context.
at System.Data.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.NewArrayInitTranslator.<>c__DisplayClass0.<TypedTranslate>b__1(Expression e)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Data.Common.CommandTrees.ExpressionBuilder.Internal.EnumerableValidator`3.Validate(IEnumerable`1 argument, String argumentName, Int32 expectedElementCount, Boolean allowEmpty, Func`3 map, Func`2 collect, Func`3 deriveName)
at System.Data.Common.CommandTrees.ExpressionBuilder.Internal.EnumerableValidator`3.Validate().........
任何人都可以帮助。
答案 0 :(得分:0)
&& objContext.CLG_taskDetail.Any(e => e.challengeId == u.id)
CLG_taskDetail为null,则在此行中,然后将该行更改为:
&& (objContext.CLG_taskDetail.Any() && objContext.CLG_taskDetail.Where(e => e.challengeId == u.id))
否则将其更改为使用'Where'子句