常数类型的原始类型! int不是原始类型?

时间:2014-04-27 01:58:36

标签: .net linq entity-framework

我在这里收到错误:

var jobOfferts = Context.JobOffertContext.Select(x => x.Id == customer.JobOfferts.FirstOrDefault(y => y.Id == x.Id).Id).ToList(); 

错误:

  

无法创建类型的常量值   ' TCCApplication.Models.JobOffertModel&#39 ;.只有原始类型或   在此上下文中支持枚举类型。

堆栈:

>    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter
> parent, ConstantExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.NewArrayInitTranslator.<>c__DisplayClassa7.<TypedTranslate>b__a5(Expression
> e)    em
> System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()   
> em
> System.Data.Entity.Core.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)    em
> System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.Internal.EnumerableValidator`3.Validate()
> em
> System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.CreateExpressionList(IEnumerable`1
> arguments, String argumentName, Boolean allowEmpty, Action`2
> validationCallback)    em
> System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.CreateExpressionList(IEnumerable`1
> arguments, String argumentName, Action`2 validationCallback)    em
> System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.CreateNewCollection(IEnumerable`1
> elements)    em
> System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.NewCollection(IEnumerable`1
> elements)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.NewArrayInitTranslator.TypedTranslate(ExpressionConverter
> parent, NewArrayExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter
> parent, ConstantExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call, DbExpression& source,
> DbExpressionBinding& sourceBinding, DbExpression& lambda)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.FirstPredicateTranslatorBase.Translate(ExpressionConverter
> parent, MethodCallExpression call)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call, SequenceMethod sequenceMethod)   
> em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
> parent, MethodCallExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberAccessTranslator.TypedTranslate(ExpressionConverter
> parent, MemberExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter
> parent, BinaryExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression
> lambda, DbExpression input)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression
> lambda, DbExpression input, DbExpressionBinding& binding)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call, DbExpression& source,
> DbExpressionBinding& sourceBinding, DbExpression& lambda)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter
> parent, MethodCallExpression call, SequenceMethod sequenceMethod)   
> em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
> parent, MethodCallExpression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter
> parent, Expression linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
> linq)    em
> System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()   
> em
> System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1
> forMergeOption)    em
> System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
> em
> System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1
> func, IDbExecutionStrategy executionStrategy, Boolean
> startLocalTransaction, Boolean releaseConnectionOnSuccess)    em
> System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
> em
> System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1
> operation)    em
> System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1
> forMergeOption)    em
> System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
> em System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()    em
> System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)   
> em System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    em
> TCCApplication.EntityFramework.CustomerEF.Update(CustomerModel
> customer) na e:\Documentos\Projetos
> pessoais\TCCApplication\TCCApplication\EntityFramework\CustomerEF.cs:linha
> 62    em
> TCCApplication.EFBusiness.CustomerBusiness.Update(CustomerModel
> record) na e:\Documentos\Projetos
> pessoais\TCCApplication\TCCApplication\EFBusiness\CustomerBusiness.cs:linha
> 26    em TestsAPI.Program.Main(String[] args) na
> e:\Documentos\Projetos
> pessoais\TCCApplication\TestsAPI\Program.cs:linha 51    em
> System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[]
> args)    em System.AppDomain.ExecuteAssembly(String assemblyFile,
> Evidence assemblySecurity, String[] args)    em
> Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   
> em System.Threading.ThreadHelper.ThreadStart_Context(Object state)   
> em System.Threading.ExecutionContext.RunInternal(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> preserveSyncCtx)    em
> System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> preserveSyncCtx)    em
> System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)    em
> System.Threading.ThreadHelper.ThreadStart()

如何修复此异常?

由于

1 个答案:

答案 0 :(得分:0)

这更接近你想要的吗?

var jobOfferts =
(
    from joc in Context.JobOffertContext
    join jo in customer.JobOfferts on joc.Id equals jo.Id into gjos
    where gjos.Any()
    select joc
).ToList();