Fetch multiple table data using Single Query in ASP.NET using Entity framework.


I want to get data from related entity based on multiple conditions in a single query

I have two tables Employee(EmpId,EmpName) and Attendance(AttId,ScanType,ScanTime,EmpId), I want to display data for each month for all Employees. In Attendance table Scan type have multiple values for in-time and out-time. I want to select smallest value as in-time and largest value as out-time for each employee and store for each employee in view model. ViewModel(EmpId,In-time,Outtime).

What will be the query for this?

 


Asked by:- MuhammadFaisal81
0
: 1841 At:- 1/19/2019 6:54:13 PM
ASP.NET C# Entity-framework-core-2







1 Answers
profileImage Answered by:- vikas_jk

I think you need to create attendance system in asp.net, as explained here

https://qawithexperts.com/questions/230/how-to-create-monthly-attendance-sheet-with-mvc

You can refer all comments/answer from this question to get the desired output.

0
At:- 1/20/2019 7:39:08 AM
i have tried the solution given in that link but it is giving me system.NullReferenceException when i try to update my view model with employee name. I am using entity framework core 2.2. may be that would be the case due to which code fails 0
By : MuhammadFaisal81 - at :- 1/20/2019 9:03:21 AM
no, it doesn't depend on EF Core or not, it a simple C# code, you are getting some data with null, use null coalescing operator ( ? :) of c# 0
By : vikas_jk - at :- 1/20/2019 12:25:54 PM
That problem is solved by including Employee table with Attendance table like this (List = _context.AttendanceTable .Include(a => a.Employee) .Where(a => a.DateAndTime.Month == Month) .OrderBy(a => a.DateAndTime) .ToList();) But now array gives problem of index out of bound if there are odd number of attendance against each employee, If its even numbered then no problem. how to solve this 0
By : MuhammadFaisal81 - at :- 1/22/2019 5:51:15 PM
Try to get maximum value of the list (array), then loop within that value 0
By : vikas_jk - at :- 1/27/2019 4:00:05 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use