views:

148

answers:

1

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 has 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.

A: 

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));
Ahmad Mageed
thnk u this wat i exepecting.
santose