I have a view model that needs to encapsulate a couple of many-to-many relationships.
I have my LINQ to Entites query that returns the appropriate list, but can't figure out how to return a list of objects.
I have a Foo table, and a Bar table. Bar has a FK to Foo.ID, and a Description string. I want to create a FooViewModel that has Foo.ID, as well as list of all the Bar.Descriptions.
public class FooViewModel {
public int ID {get; set; }
public IEnumerable Descriptions { get; set; }
}
var all = from f in ctx.Foo.Include("Bar")
select new FooViewModel
{
ID = f.ID,
Descriptions = <insert magic here>
};
What am I missing?