PC Review


Reply
Thread Tools Rate Thread

Bug in the Entity Framework?

 
 
PReichert
Guest
Posts: n/a
 
      27th Oct 2008
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Framework: returning the Entity with the Min() cost Markla Microsoft ADO .NET 0 4th Sep 2009 02:59 AM
Entity Framework - entity with multiple foreign keys to same table CGatto Microsoft ADO .NET 1 7th Aug 2009 07:51 PM
Entity Framework - Reassigning child entity's parent Norm Microsoft ASP .NET 3 6th Jul 2009 08:28 PM
How to relate a SQL based entity with an Object based entity in Entity Framework markla Microsoft ASP .NET 1 6th Oct 2008 10:42 AM
Entity Framework =?Utf-8?B?ZGFGb3U=?= Microsoft ADO .NET 0 29th Aug 2007 10:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 PM.