0

How can I use where condition in include? ProgressItems is ICollection<> object. I want to get whole Goal object with filtered items. How can I resolve it?

        return _dbContext.Goals
            .Include(p => p.GoalExpectation)
            .Include(p => p.ProgressItems.Where(r => r.Value > 100))
            .SingleOrDefault(p => p.Id == id);

I get such 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. Parameter name: path

Jacek
  • 11,661
  • 23
  • 69
  • 123

2 Answers2

1

The include Statement expects a navigation property (as the error says). Purely syntactically it seems correct what you do, but it appears to be sementically wrong, because Where does not return a navigation property.

bash.d
  • 13,029
  • 3
  • 29
  • 42
0

You can't, you'd have to limit it by using a query that can get the included items with the filter and assign that to your Goal object.

gmn
  • 4,199
  • 4
  • 24
  • 46