0

I need to get products with cover picture. But when i add pic => pic.IsCover it's throw exception.Otherwise there is no problem. How can i fixed it?

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. Parametre adı: path

Thanks to all

_db.ProdSmartSorts
    .Where(x => catIds.Contains((int)x.Product.CategoryId))
    .OrderBy(x => x.ProdSmartId)
    .Select(x => x.Product)
    .Include(p => p.Pictures.Where(pic => pic.IsCover))
    .Skip(prodCount * (pageNumber - 1))
    .Take(prodCount)
    .ToList();
Jason Boyd
  • 6,839
  • 4
  • 29
  • 47
Yargicx
  • 1,704
  • 3
  • 16
  • 36

2 Answers2

2

Entity Framework does not support filtering with the Include method. You can vote for it here, though: https://entityframework.codeplex.com/workitem/47

Jason Boyd
  • 6,839
  • 4
  • 29
  • 47
0

Does placing the .Include() method call directly after the DbSet work? i.e.

_db.ProdSmartSorts
 .Include(p => p.Pictures)
 .Where(x => catIds.Contains((int)x.Product.CategoryId))
 .OrderBy(x => x.ProdSmartId)
 .Select(x => x.Product)
 .Skip(prodCount * (pageNumber - 1))
 .Take(prodCount)
 .ToList();

I think the Include method is only available on the DbSet objects within the dbContext. If you try and put it further down the chain you only have methods that are available to IQueryable or IEnumerable objects dependant on the circumstances.

Also, to my knowledge you can't use the Include function to filter, as you attempted. So you will have to load all images related Picture entities.

EDIT: Sorry - just realised that this question is specifically asking for filtering on the Include() method. Please disregard.

Bunjy
  • 130
  • 7