I am trying to use custom framework for EF but I am having a problem that I dont understand. The error is below. It seems very obvious but I am not sure how to fix it
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.
_menuRepository.GetAll(d => d.DateToDisplay <= DateTime.Today).OrderByDescending(d=>d.Id).Take(100).ToList();
public virtual IList<T> GetAll(params Expression<Func<T, object>> navigationProperties)
using (var context = new DBEntities())
IQueryable<T> dbQuery = context.Set<T>();
//Apply eager loading
foreach (Expression<Func<T, object>> navigationProperty in navigationProperties)
dbQuery = dbQuery.Include<T, object>(navigationProperty); //**** It throws the exception here
list = dbQuery
An Expression in EF is expected to be a lambda that retrieves a property of an object. In your example
d => d.DateToDisplay <= DateTime.Today
is a predicate - it evaluates to a Boolean value: that's why Include cannot determine which property to "include".
I guess you've confused Include with a LINQ Where clase. Apparently, this should work:
_menuRepository.GetAll(d => d.DateToDisplay).OrderByDescending(d=>d.Id).Take(100).ToList();
if only type T has property DateToDisplay.