P
PReichert
I have just started trying the Entity Framework in .NET 3.5 and the following
query doesn't seem to work at all:
List<string> parties = (from p in entities.Parties
where p.type == (int)ptyType
select p.ptyid).ToList();
ptyType is an enum value. It seems that if I replace the code for something
like the following it works:
var ptyTypeInt = (int) ptyType;
List<string> parties = (from p in entities.Parties
where p.type == ptyTypeInt
select p.ptyid).ToList();
The exception that I get in the first query is the following:
System.NotSupportedException was unhandled by user code
Message="Unable to create a constant value of type 'Closure type'. Only
primitive types ('such as Int32, String, and Guid') are supported in this
context."
Source="System.Data.Entity"
StackTrace:
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.MemberAccessTranslator.TypedTranslate(ExpressionConverter parent, MemberExpression 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.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression 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.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression 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.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression 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.TranslateLambda(LambdaExpression lambda, DbExpression input)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding&
sourceBinding, DbExpression& lambda)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression 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.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding&
sourceBinding, DbExpression& lambda)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression 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.Convert()
at
System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1
forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1
forMergeOption)
at
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
...
Has anyone seen this before?
query doesn't seem to work at all:
List<string> parties = (from p in entities.Parties
where p.type == (int)ptyType
select p.ptyid).ToList();
ptyType is an enum value. It seems that if I replace the code for something
like the following it works:
var ptyTypeInt = (int) ptyType;
List<string> parties = (from p in entities.Parties
where p.type == ptyTypeInt
select p.ptyid).ToList();
The exception that I get in the first query is the following:
System.NotSupportedException was unhandled by user code
Message="Unable to create a constant value of type 'Closure type'. Only
primitive types ('such as Int32, String, and Guid') are supported in this
context."
Source="System.Data.Entity"
StackTrace:
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.MemberAccessTranslator.TypedTranslate(ExpressionConverter parent, MemberExpression 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.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression 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.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression 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.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression 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.TranslateLambda(LambdaExpression lambda, DbExpression input)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding&
sourceBinding, DbExpression& lambda)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression 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.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding&
sourceBinding, DbExpression& lambda)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at
System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression 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.Convert()
at
System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1
forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1
forMergeOption)
at
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
...
Has anyone seen this before?