Is it possible to eagerly load related entities, but to not have the related entities of the related entities be loaded?
In my case, I have a set of flags to determine which related entities should be loaded:
[Flags]
public enum FooRetrievalOptions
{
None = 0,
Bar = 1,
Baz = 2,
All = Bar | Baz
}
I create an IQueryable<Foo> and successively .Include depending on which flags have been set.
IQueryable<Foo> query = context.Foos;
if (fooRetrievalOptions.HasFlag(FooRetrievalOptions.Bar))
{
query.Include(f => f.Bar);
}
if (fooRetrievalOptions.HasFlag(FooRetrievalOptions.Baz))
{
query.Include(f => f.Baz);
}
List<Foo> foos = query.ToList();
The problem with this is that it can create cycles when serializing depending on the navigation properties on Bar and Baz.
I simply want to load associated entities in one database hit without their own related entities being loaded as well. Is this possible?
IgnoreDataMemberAttribute
if you are using .NET 4.5 ? - Maxime