I have a table that has a set of data in it, as follows:
Notice the above results are gathered by the following SQL query:
select * from Logs wh
As @Ivan Stoev already mentioned: OrderBy before Distinct / GroupBy is ignored by LINQ to Entities sql translator.
But if you must use it, use it before the OrderBy
var logs = db.Logs.Where(x => x.RegisterationId == EnrollNumber && x.Date >=
StartDate && x.Date <= EndDate && x.isIgnore != true).Distinct().OrderBy(x => x.DateTime).ToList();
Excluding the Distinct()
should give you the appropriate list:
var logs = db.Logs.Where(x => x.RegisterationId == EnrollNumber && x.Date >=
StartDate && x.Date <= EndDate && x.isIgnore != true).OrderBy(x => x.DateTime).ToList();
.Distinct
destroys order. Switch the position of the Distinct
and the OrderBy
calls.