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: 739
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: 739
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
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down