Print Page | Close Window

Linq anonymous type sub collection query

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2655
Printed Date: 23-Apr-2024 at 7:58pm


Topic: Linq anonymous type sub collection query
Posted By: tersiusk
Subject: Linq anonymous type sub collection query
Date Posted: 09-May-2011 at 5:49am
Hi I'm trying to execute the following query but the result has the following error.

Also when I run this with normal entity framework the code executes and results are fine. Is this a bug? If so are there any kind of work around you can suggest?

"Unable to cast object of type 'System.Object[]' to type 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`3[System.Int64,System.String,System.String]]'."
 var query = (EntityQuery)(from makes in em.VehicleMakes
                                      orderby makes.MakeName
                                      select new
                                      {
                                          Key = makes.VehicleMakeId,
                                          Name = makes.MakeName,
                                          Description = makes.MakeCode,
                                          Children = from model in makes.VehicleModels
                                                     select new
                                                     {
                                                         Key = model.VehicleModelId,
                                                         Name = model.ModelName,
                                                         Description = model.ModelCode
                                                     }
                                      });



Replies:
Posted By: sbelini
Date Posted: 09-May-2011 at 3:57pm
Hi Tersius,
 
I have verified and this is indeed a bug.
We have already filed a bug and I will let you know as soon as we have a fix for it.
 
Regards,
Silvio.


Posted By: tersiusk
Date Posted: 10-May-2011 at 12:04am
Hi

Thanks. In the meantime is there any other way I can get the same sort of results? 

edit: It seems to work if you use a concrete type.

Regards


Posted By: sbelini
Date Posted: 10-May-2011 at 12:47pm
Hi Tersius,
 
Try running the query against the CacheOnly. (You will need to load all VehiclesMakes and VehicleModels in the cache first - but that you do with your query anyhow)
 
Silvio.


Posted By: DanOve
Date Posted: 05-Dec-2013 at 12:09am
Hi.

I get the same exception when I try running this example in DevForce 2012.
Is this bug really fixed?

Best Regards

Dan Ove


Posted By: kimj
Date Posted: 05-Dec-2013 at 11:09am

The bug is marked as fixed, although it looks like the defect report didn't accurately describe the situation, as I see the exception still too.  For now, the workaround is a CacheOnly query as described above, or removing the nested anonymous projection (on VehicleModels in the query above).



Posted By: DanOve
Date Posted: 05-Dec-2013 at 11:20pm
Hi Kimj

Thanks for your answer. Do you plan to support nested anonymous projection? It's super useful for querying large linked tables and optimize performance.

Dan Ove


Posted By: kimj
Date Posted: 06-Dec-2013 at 8:07am
We've added a new bug report for the issue, but I don't have any information yet on when, or if, it will be fixed.


Posted By: DanOve
Date Posted: 16-Jan-2014 at 3:49am
Hi Kimj

Any news or release date?


/Dan Ove



Print Page | Close Window