If I am interpreting your question correctly, you want to order by the Count
of Entry
for a given member where the Entry
meets your timestamp criteria, like this:
var query = repository.Members
.OrderByDescending(m =>
m.Entry
.Where(e =>
e.TimeStamp.Day <= timeComparison))
.Count());
To debug/verify the counts that EF is returning, you can use a slightly modified version of the same, but select an anonymous type that contains the Member
Id and a count of entries that match the criteria:
var results = repository.Members
.OrderByDescending(m =>
m.Entry
.Where(e =>
e.TimeStamp.Day <= timeComparison)
.Count())
.Select(m => new {
MemberId = m.Id,
Count = m.Entry.Where(e =>
e.TimeStamp.Day <= timeComparison)
.Count()
});