Let's say I have two simple entities:
class Cat
{
int Id;
string Name;
ICollection<CatRelation> ToRelations;
ICollection<CatRelation> FromRelations;
}
class CatRelation
{
int FromCatId;
int ToCatId;
Cat FromCat;
Cat ToCat;
string RelationType;
}
What I would like to do is load all the Cats and their relations, and have the navigation properties work throughout the whole graph. So far I have something like this:
context.Cats.Include(cat => cat.ToRelations)
.Include(cat => cat.FromRelations)
.ToList()
After this the context is disposed of. Further down the line the list is iterated through. This works fine for getting to the relations -entities, but if I, for example, iterate over the Cats and then try to iterate over all their relations, the other end of the CatRelation is there, but its navigation properties won't work (ContextDisposed). As in, given the following cat var cat1 = cats.First().ToRelations.First().ToCat, if I try to access cat1.ToRelations, I get a ContextDisposed -exception.
So is there a way for me to ask the context to fix all these navigation properties (because I know I have loaded all the Cats of all the CatRelations), before disposing of the context?