Hi
I have below data . Since all students are absent in 3B . Result should be 1 . I want thru Linq query.
| Group | Student | Present |
| 2A | 2 | Y |
| 2A | 5 | Y |
| 3B | 2 | N |
| 3B | 5 | N |
| 3B | 3 | N |
| 4A | 2 | Y |
| 4A | 5 | N |
Thanks
Hi
I have below data . Since all students are absent in 3B . Result should be 1 . I want thru Linq query.
| Group | Student | Present |
| 2A | 2 | Y |
| 2A | 5 | Y |
| 3B | 2 | N |
| 3B | 5 | N |
| 3B | 3 | N |
| 4A | 2 | Y |
| 4A | 5 | N |
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Jun 22, 2023, 5:35 AM
Deepak RawatPosted Jun 22, 2023, 10:05 AM
You can use LINQ to query the data and retrieve the count of groups where all students are absent (Present = 'N'). Here's an example LINQ query that accomplishes this:
Output: 1
The LINQ query groups the data by the "Group" field and then counts the number of groups where all students have "N" for the "Present" field. In this case, the result is 1 because only the group "3B" has all students absent.
Brahma Prakash ShuklaPosted Jun 22, 2023, 7:43 AM
To get the count of groups where all students are absent using a LINQ query, you can follow these steps:
AttendanceRecord:AttendanceRecordobjects and populate it with your data:Groupproperty and check if all students in each group are absent:Explanation of the query:
GroupBymethod groups the attendance records by theGroupproperty.Countmethod is used to count the number of groups where all students are absent. TheAllmethod is applied to each group, checking if all thePresentvalues are equal to "N".Remember to adjust the property names and data types in the
AttendanceRecordclass to match your actual data structure.The variable
resultwill contain the count of groups where all students are absent, which in this case is 1.Rajkiran SwainPosted Jun 22, 2023, 4:21 AM
Tuhin PaulPosted Jun 22, 2023, 2:06 AM
LINQ query to achieve the desired result
The output will be 1, indicating that all students are absent in group 3B.
Mohamed Azarudeen ZPosted Jun 21, 2023, 4:36 PM
Hi ramco
you can use LINQ to query the data. Here's an example of how you can achieve this:
The LINQ query first groups the data by the
Groupproperty usingGroupBy(). Then, it counts the number of groups where all students are absent by applying a condition withAll()to check if thePresentproperty of all elements in each group equals "N". The result is the count of such groups.