New Posts New Posts RSS Feed: Linq anonymous type sub collection query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Linq anonymous type sub collection query

 Post Reply Post Reply
Author
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
DanOve View Drop Down
Newbie
Newbie


Joined: 20-Sep-2013
Posts: 3
Post Options Post Options   Quote DanOve Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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).

Back to Top
DanOve View Drop Down
Newbie
Newbie


Joined: 20-Sep-2013
Posts: 3
Post Options Post Options   Quote DanOve Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DanOve View Drop Down
Newbie
Newbie


Joined: 20-Sep-2013
Posts: 3
Post Options Post Options   Quote DanOve Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jan-2014 at 3:49am
Hi Kimj

Any news or release date?


/Dan Ove
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down