Can someone please explain why following query returns list of 8 vessels?
var vessels = await db.Vessels
.Include(m => m.Images.Select(c => c.Activity))
.Include(m => m.VesselAddresses.Select(c => c.Address))
.Where(m => m.Images.Any(c => c.Activity.Active))
.Where(m => m.Activity.Active)
.Where(m => m.Listed)
.Where(m => m.Activity.User.Active)
.OrderBy(m => Guid.NewGuid())
.Take(4)
.ToListAsync();
If i remove Include(m => m.VesselAddresses.Select(c => c.Address))
or OrderBy
from the query, then it works just fine and returns 4 records, but if i leave it as it is, then it returns 8 records, even i specified Take(4)
EDIT
This is almost the same query for apartments table, but this query works just fine and always returns 4 rows:
var apartments = await db.Apartments
.Include(m => m.Images.Select(c => c.Activity))
.Include(m => m.Address)
.Where(m => m.Images.Any(c => c.Activity.Active))
.Where(m => m.Activity.Active)
.Where(m => m.Listed)
.Where(m => m.Activity.User.Active).OrderBy(m => Guid.NewGuid())
.Take(4)
.ToListAsync();