question

anilkumar-7193 avatar image
0 Votes"
anilkumar-7193 asked ZhiLv-MSFT commented

Linq Query join with multiple table with order by clause

var filterresult = (from e in employees
select new EmpAttendanceViewModel
{
AId = e.AId,
EmpId = e.Empid,
Name = e.name,
offid = (from att in empAttendances where att.EmpAId == e.AId select e.OffMasId).FirstOrDefault(),
Time = (from att in empAttendances where att.EmpAId == e.AId select (att.TOut - att.TIn).ToString()).FirstOrDefault(),//(t1.TOut - t1.TIn).ToString() //
}).ToList().OrderBy(e=>e.offname).ThenBy(d=>d.dat);;


Do you mean you want to order the result with offname and attdate? If that is the case, can you tell us which table the offname and attdate belong to?

Besides, since this is a new question, and the original question is old and have been solved, I suggest you could close the current thread and post a new thread about your new problem. Then we can find the new problem more easily, and help you solve it.


Above is my last thread and in above employee has offid an attendance table has adate by which i want to apply order by clause

dotnet-aspnet-core-mvc
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @anilkumar-7193,

Which table do the offname and attdate belong to? As we can see that, in the EmpAttendanceViewModel model, it doesn't contain the offname and the date property. Do you mean you want to sort the result based on the EmpAttendanceViewModel's offid and Time property?

0 Votes 0 ·

offname belong to offmas which in define in attendanceviewmodel and attdate is in empattendance

I have apply orderby after tolist() but it is not working

0 Votes 0 ·

Hi @anilkumar-7193,

 var filterresult = (from e in employees
 select new EmpAttendanceViewModel
 {
 AId = e.AId,
 EmpId = e.Empid,
 Name = e.name,
 offid = (from att in empAttendances where att.EmpAId == e.AId select e.OffMasId).FirstOrDefault(),
 Time = (from att in empAttendances where att.EmpAId == e.AId select (att.TOut - att.TIn).ToString()).FirstOrDefault(),//(t1.TOut - t1.TIn).ToString() //
 }).ToList();

Can't reproduce the problem on my side, can you post the EmpAttendanceViewModel class and the related property (then we can know the data type)? And if possible, I suggest you could set break point in the above code and show us the filterresult data.


0 Votes 0 ·

0 Answers