Reputation: 1657
If I have classes Account
, AccountImage
and Image
public class Account{
public virtual List<AccountImage> AccountImages{get;set;}
}
public class AccountImage{
public virtual Image Image {get;set;}
}
public class Image{
public string ImageUrl {get;set;}
}
I have an Account
object want to load Image
references of the AccountImages
collection.
I can load AccountImages
like this,
Db.Entry(v.acc).Collection(e => e.AccountImages).Load();
but how ca I load Image
without resorting to
foreach(var ai in v.acc.AccountImages){
Db.Entry(ai).Reference(e => e.Image).Load();
}
and inducing multiple db hits?
Upvotes: 1
Views: 238
Reputation: 11544
To avoid foreach loop in explicit load, you can load navigation properties eagerly:
var acc = db.Accounts.Include(a => a.AccountImages.Select(ai => ai.Image));
Upvotes: 2