I'm not sure where to start doing this with entity framework. Here are samples of the table data. The tables are created via code first.
I have 5 tables:
Id - Person
12 - John
13 - Sarah
14 - Bob
15 - Frank
Id - Package
1 - Standard
2 - Extra
3 - Gold
4 - Off Season
Id - Features
21 - Feature A
22 - Feature B
23 - Feature C
24 - Feature D
Link Tables
PersonId - PackageId
12 - 1
12 - 4
13 - 3
14 - 2
15 - 1
15 - 2
PackageId - FeatureId
1 - 21
1 - 22
2 - 21
2 - 22
2 - 23
3 - 21
I know that I can find out a Person's Features like this:
var person = _db.Persons
.Where(p => p.Id == id)
.Include(p => p.Packages)
.Include("Packages.Features")
.SingleOrDefault();
However I would like to get a ViewModel class or even a list that has only these columns:
PersonId Person FeatureId Feature
12 - John - 21 - Feature A
12 - John - 22 - Feature B
I know I can do it with SQL. I'm just not sure how to do it with Linq and Entity Framework. What's the best practice to do that?