I am using EF 7 with the query as below.
var query = db.Contracts
.Include(s => s.ContractType).ThenInclude(s => s.Header)
.Include(s => s.ContractUsers).ThenInclude(s => s.User)
.AsQueryable();
query = query.OrderBy(s=>s.EffectiveDate).ToList();
Above query is returning results with ContractUsers collection as empty but ContractType filled out.
If I remove OrderBy
query, then it returns the ContractsUsers collection. It's strange, can someone help me how to fix this? I need to have the ordering done in sql.