Consider following entity model:
public class Parent
{
public virtual FirstChild FirstChild { get; set; }
public virtual SecondChild SecondChild { get; set; }
}
In my code, I have loaded Parent
entity:
Parent parent = <loaded in some way>;
To explicitly load its navigational properties, I use
db.Entry(parent).Reference(p => p.FirstChild).Load();
db.Entry(parent).Reference(p => p.SecondChild).Load();
But this results in two DB queries.
Question: is there a more elegant way, that would allow to explicitly load more than one navigational property in single query?
If I didn't have parent
loaded, I would do eager loading:
Parent parent = db.Parents
.Include(p => p.FirstChild)
.Include(p => p.SecondChild)
.FirstOrDefault();
but, as I mentioned, I already have it loaded without related entities (and I can't modify the loading code).