I have 2 classes:
Employee
EmployeeDetails
I would like to have a list with first ordering of Employee then sort it, then EmployeeDetails orderby and then sort it.
I was thinking of something like this:
var result = _db.Employee
.OrderBy( e => e.EmpName )
.Sort('DepartmentId') // using the diff property
.ThenBy( ed => ed.EmpAddress )
.Sort('PostCode'); // using the diff property
I need to first order by EmpName
from Employee then Sort it after from those resultset I want to orderby EmpAddress and Sort it and then return the resultset.
Is this even possible? Can it be done without using Lambdas? Are the other approaches?
Is the following code what you're looking for?
var result = _db.Employee
.OrderBy(e => e.EmpName)
.ThenBy(e => e.DeptartmentId)
.ThenBy(e => e.EmpAddresss)
.ThenBy(e => e.PostCode);
You are looking for:
var result = _db.Employee
.OrderBy( e => e.EmpName ) //OrderBy and SortBy empname Ascending
.ThenBy( ed => ed.EmpAddress ); //orderby address ascending
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With