I want to retrieve a DB set with as few obsolete-data as possible, so I wrote the following include-statement
using (var context = this.Container.Resolve<IDbContextScope>()
{
var databaseRequirements = context.Requirements
.Include(x => x.RequirementVersions.MaxBy(y => y.Version))
.Include(x => x.RequirementVersions.Select(y => y.RequirementDetails));
}
so later I can use my foreach;
foreach (MyRequirement requirement in databaseRequirements)
{
var databaseRequirementDetails = requirement.RequirementVersion.FirstOrDefault()?.RequirementDetails;
// Some more code that uses the var...
}
The database that is used here has 3 tables, Requirements
, RequirementVersions
, RequirementDetails
. 1 Requirement
has many RequirementVersions
and 1 RequirementDetails
has many RequirementVersions
.
I initially ran with the MaxBy()
from the .Include()
-statement in place of the .FirstOrDefault()
, but that'll retrieve all the old versions of a requirement, which I don't need in this particular method (and depending on the amount of requirements/requirementversions may slow the whole method down tremendously).
On to the actual problem; When I run this, I get
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 couldn't find anything on how to write this statement in a way it's accepted and does what I intend to do. It's an optimization-effort, so as long as it runs quicker than the alternative I'll settle.
Edit: It is not a duplicate of the linked article because the linked article's accepted answer returns a single object, whereas I need a list of objects who's lists contain a single object.