开发者

compare two list in linq

i'm having to two tables, which i need to compare both the table.

Let say table 1) Student profile 2) staff list.-- in this each staff h开发者_开发技巧as their student id , like many row

I need to get the current staff who log in's student id which may be many row.

And the resulted student profile from table 1.


Based on what you're describing the Staff table has multiple entries (at least 1) for each staff member, and those entries have a unique StudentID mapping staff to student. Something like this:

StaffID = 1, StudentID = 3
StaffID = 1, StudentID = 21
StaffID = 2, StudentID = 45
...

With the above type of setup, you can grab the list of students that belong to the currently signed in staff user, then query the student table for matching students:

 int staffID = 1; // current staff user
 var staffStudents = StaffTable.Where(s => s.StaffID == staffID)
                                      .Select(s => s.StudentID);
 var query = StudentTable.Where(student =>
                        staffStudents.Any(id => id == student.StudentID));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜