Reputation: 4583
Consider the following simple case.
class Adult
{
public List<Children> Children { get; private set; }
}
If you are passed an instance of Parent that is tracked by Entity Framework and this instance has an empty list of children, is there any way that you can programatically determine if the Children collection is empty due to the parent actually not having children or if the empty list is due to these data not being fetched? I assume that EF has some form of knowledge of it, since we are supposed to be able to retrieve a parent without fetching the children and make changes to Parent.Name and such and invoke SaveChanges without EF deleting the children just because the Children collection is empty at the time of save.
I've looked at TrackedEntities and EntityStates, but I don't see how to make this determination.
Upvotes: 2
Views: 49
Reputation: 30813
var isLoaded = context.Entry(adult).Collection(p => p.Children).IsLoaded;
and
context.Entry(adult).Collection(p => p.Children).Load();
Upvotes: 2