Am using Entity framework to connect database with my asp.net application. Here I’ve a Foreign key table which has two columns, StaffId and SectionId. Here StaffId is the Primary key of Staff table and SectionId is the Primary key of Sections table. I have values in this table like
StaffId SectionId
------- ---------
1 1
2 5
5 8
1 5
1 8
here I know the StaffId and I need to get all the SectionIds for this corresponding staffid(eg. 1,5 and 8 for staff 1 here).
If I want to know the details with First method, with the known StaffId I can do like,
DataObject.Entities dataEntities=new DataObject.Entities();
DataObject.Section section = dataEntities.Sections.First(s=>s.Staffs
.Select(ss=>ss.StaffId).Contains(staffId));
with this I can get the information about the first section that matches with the StaffId.(ex:info about sectionid=1 here)
In the same way I tried to get all the sectionIds for a particular staffId like,
List<int> sectionIds = dataEntities.Sections.Where(s => s.Staffs.Where
(ss => ss.StaffId == staffId)).Select(sec=>sec.SectionId);
but its not working, can anyone help me here
1 Answer