Link attributes of related objects

I am getting a list of entities like this:

var riscregions = db.RiscEntranceDetails.OrderBy(r => r.RiscEntranceID).Include(r => r.RiscEntrance).Include(r => r.RiscRegion);

      

However, I need to get more deeply related entity attributes like:

<td>@item.RiscEntrance.ID</td>
<td>@item.RiscEntrance.Personnel.Name</td>
<td>@item.RiscEntrance.EntranceDateTime</td>
<td>@item.RiscEntrance.ShiftWork.ShiftGroup.TextID</td>

      

How can I contact them? Any suggestions including linq or some other workarounds like extensions and helpers are welcome.

+3


source to share


2 answers


You can do it:

var riscregions = db.RiscEntranceDetails
                .OrderBy(r => r.RiscEntranceID)
                .Include(r => r.RiscEntrance)
                .Include(r => r.RiscEntrance.Personnel)
                .Include(r => r.RiscEntrance.ShiftWork.ShiftGroup)

      



You only need to use Select

in an expression Include

if you need to select the children of the collection.

+2


source


http://msdn.microsoft.com/en-us/data/jj574232.aspx



Look forward to loading multiple levels. You can use .Select()

in your .Include()

lambda.

+1


source







All Articles