Using EntityFramework Include with OfType

Viewed 1472

In my query i need to include (to avoid lazy loading) a list of entities.

query.Include(x => x.ActionValues.Select(a => a.ActionValueDetails));

this works without any problems but in some cases i need another eager loaded property of ActionValueDetail. ActionValueDetail is a base class of many other implementations of it. My code looks like this for these cases:

query.Include(t => t.ActionValues.Select(a => a.ActionValueDetails.OfType<ActionValueDetailSpecial>().Select(d => d.SpecialDetail)));

But this always throws an exception.

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

I don't know how to solve this problem. Using lazy-loading or projection is not an option for me in this case. We need this for very large exports to ensure all data is loaded before we're writing into a stream.

Any help would be great!

0 Answers
Related