简体   繁体   中英

Entity Framework LINQ Include - Child Entities

I am loading the child entity UserStarted from my TransactionDetails

var result = (from A in context.Transactions.Include(_ => _.TransactionDetails.Select(us => us.UserStarted))
              select A).SingleOrDefault();

Now I want to load another entity, but I don't know how. The entity is similar to UserStarted , it's the UserEnded also from TransactionDetails

Thank you very much

You can chain multiple include predicates together:

var result = context.Transactions
  .Include(transaction => transaction.TransactionDetails.Select(us => us.UserStarted))
  .Include(transaction => transaction.TransactionDetails.Select(us => us.UserEnded))
  .SingleOrDefault();

You can also try

 var result = (from A in context.Transactions.Include(_ => _.TransactionDetails.Select(us => new { UserStarted  = us.UserStarted, UserEnded = us.UserEnded }))
select A).SingleOrDefault();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM