LINQ-select and LINQ-GroupBY-select returning different types
Posted on 2013-11-13
I am fairly new to all of this and plodding along with some modicum of succes using LINQ and MVC4 however I have run into a problem whereby
1. I successfully select from the Entity Framework using
Dim lst1 = (From n In db.MenuDrivers Where n.MajorNode = "Applications" And n.MinorNode = "Driver" Select n)
This returns a list of type: System.Data.Objects.ObjectQuery`1[Mvc.MenuDriver]"
of which I can pass to my layout as an View
2. I need to constrain the result and only send unique groups so I used
Dim lst = (From n In db.MenuDrivers Where n.MajorNode = "Applications" Group n By Key = n.MinorNode Into Group Select TotalGroups = Group)
which also works but it returns the lst as type System.Collections.Generic.List`1[System.Collections.Generic.IEnumerable`1[Mvc.MenuDriver]]
and I cannot pass this to the layout using the View any longer.
I get an error
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[System.Collections.Generic.IEnumerable`1[Mvc.MenuDriver]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Mvc.MenuDriver]'
How can I get the correct tyupe back from the group LINQ?