Author |
Share Topic Topic Search Topic Options
|
tersiusk
Newbie
Joined: 03-Nov-2010
Posts: 20
|
Post Options
Quote Reply
Topic: Linq anonymous type sub collection query 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
}
});
Edited by tersiusk - 09-May-2011 at 6:22am
|
|
sbelini
IdeaBlade
Joined: 13-Aug-2010
Location: Oakland
Posts: 786
|
Post Options
Quote Reply
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.
|
|
tersiusk
Newbie
Joined: 03-Nov-2010
Posts: 20
|
Post Options
Quote Reply
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
Edited by tersiusk - 10-May-2011 at 2:13am
|
|
sbelini
IdeaBlade
Joined: 13-Aug-2010
Location: Oakland
Posts: 786
|
Post Options
Quote Reply
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.
Edited by sbelini - 10-May-2011 at 12:52pm
|
|
DanOve
Newbie
Joined: 20-Sep-2013
Posts: 3
|
Post Options
Quote Reply
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
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
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).
|
|
DanOve
Newbie
Joined: 20-Sep-2013
Posts: 3
|
Post Options
Quote Reply
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
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
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.
|
|
DanOve
Newbie
Joined: 20-Sep-2013
Posts: 3
|
Post Options
Quote Reply
Posted: 16-Jan-2014 at 3:49am |
Hi Kimj
Any news or release date?
/Dan Ove
|
|