Consider I have the following snippet:
IQueryable<BaseEntity> someQueryble = ApplicationDbContext.BaseEntities;
var randomQueryable = someQueryable.OfType<RandomEntity>()
.Include(prop => prop.SomeRandomNavProp)
.OrderBy(prop => prop.Id);
BaseEntities
is just DbSet
from ApplicationDbContext
from EF 6.
RandomEntity
inherits from BaseEntity
(Table-Per-Type hierarchy)
Then, something strange happens:
randomQueryable.Take(10).Count();
10
randomQueryable.Take(10).ToList().Count;
20
When Include
is removed, everything works fine. Why does .include
affect on ToList
and how can I resolve that?
Edit: the generated SQL:
Attention - it's from production datababase, so readability can hurt. First query is about Count
and the second one - about ToList()