0

Ok, I have tri-leveled entities with the following hierarchy:
User -> RegisteredVehicle -> MakeSource
----------------------------------->ModelSource
----------------------------------->YearSource (Yes I know, a lookup table for years how horrible.)

A user can have a registered vehicle which itself can have a fk from MakeSource and a fk from ModelSource which holds relevant vehicle data. (Name, Cylinders, Transmission etc)

How can I use a linq query to select a user's information, any registered vehicles he has along with the meta data for the makesource and modelsource tables?

var entity = context.AspNetUsers.Include(P => P.RegisteredVehicles
                .Select(P => P.MakeSource));  

This gets me as much as the makes but I am still out of luck with the model sources and year sources.

enter image description here

Adrian
  • 3,332
  • 5
  • 34
  • 52
  • Write a second and third include. http://stackoverflow.com/questions/15764572/ef-linq-include-multiple-and-nested-entities – Rand Random Jul 29 '14 at 20:56

1 Answers1

1

You should just be able to chain the includes:

var entity = context.AspNetUsers.Include(P => P.RegisteredVehicles
            .Select(P => P.MakeSource)).Include(P => P.RegisteredVehicles
            .Select(P => P.ModelSource)).Include(P => P.RegisteredVehicles
            .Select(P => P.YearSource));  
Bcpouli
  • 225
  • 3
  • 14