0

Let's suppose I've an Entity like this:

Public classs Blog{
    public int x,
    public bool y,
    public virtual ICollection<someType> someTypes
    public virtual ICollection<Post> Posts
}

Now I want to fire the following query:

repository.findBy(
    blogs => blogs.y, 
    blogs => blogs.someTypes, 
    blogs => blogs.Posts.where(someVar => someVar.someField == someValue)
).select()

someField is a property of Post.

where findBy is :

IQueryable<T> FindBy(Expression<Func<T, bool>> predicate = null, params Expression<Func<T, object>>[] includes);

It gives the following error:

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

NoviceCoder
  • 31
  • 2
  • 8
  • 1
    x is no navigation property, and Posts.where() is also no navigation property. – DevilSuichiro Jun 09 '16 at 06:46
  • 1
    Conditional include is not yet implemented by EF team, The error you getting you are not including the types defined in the class. You can include only ICollection or Virtual property – Eldho Jun 09 '16 at 07:30

1 Answers1

0

Try removing this blogs => blogs.y

This is not a navigation property, You can only include Navigation property in the include statement.

The columns are populated by default, unless you use a projection.

repository.findBy(blogs => blogs.someTypes, blogs => blogs.Posts).select()

Note* Conditional include is not yet implemented by EF team
This is still a work item in EF team, you could vote here

Note that it is not currently possible to filter which related entities are loaded. Include will always bring in all related entities. Msdn Reference

Eldho
  • 7,795
  • 5
  • 40
  • 77