Last post Oct 28, 2019 02:18 PM by polachan
Oct 28, 2019 11:30 AM|polachan|LINK
I want to add order by clause in my LINQ
List<EmployeeModel> EmpList = _iRepo.GetAll().Where(u => u.EmpLeaveDate >= _dtfrom && u.EmpLeaveDate <= _dtto).
Select(u => new EmployeeModel
DepotNo = u.DepotNo,
EmployeeName = u.EmployeeName,
LeaveDate = u.EmpLeaveDate.ToString()
How can I add order by clause please help
.order by u.empleavedate
Oct 28, 2019 12:18 PM|PatriceSc|LINK
What if you try to add OrderBy between the Where and Select clause ?
.Select(u => new EmployeeModel
For now I suspect you tried after the Select the problem being likely that you can't properly sort on the LeaveDate
My personal preference is to use "native" data as much as I can and to let the value to string conversion happen at the UI level. For example here as soon as you want to actually use the LeaveDate (for example to show a "leaved since x days" message) you
are stuck with a string you would have to convert back rather than just the "real" value you could use.
Oct 28, 2019 02:18 PM|polachan|LINK
Many Thanks. fine
No I am keeping datetime column and string column. I will sort datetime column and make it hidden and then will show string column only in Datatable
Many Thanks Patrice