Asp.net 从外键表中获取值
我使用实体框架将数据库连接到我的asp.net应用程序。这里有一个Asp.net 从外键表中获取值,asp.net,entity-framework,Asp.net,Entity Framework,我使用实体框架将数据库连接到我的asp.net应用程序。这里有一个外键表,它有两列,StaffId和SectionId。这里的StaffId是Staff表的主键,SectionId是Sections表的主键。我在这个表中有如下值 StaffId SectionId ------- --------- 1 1 2 5 5 8 1 5 1 8 这里我知道
外键表
,它有两列,StaffId和SectionId
。这里的StaffId
是Staff
表的主键,SectionId
是Sections
表的主键。我在这个表中有如下值
StaffId SectionId
------- ---------
1 1
2 5
5 8
1 5
1 8
这里我知道StaffId
,我需要获得该对应StaffId的所有部分ID
(例如这里的职员1的1、5和8)
如果我想用First
方法了解细节,用已知的StaffId我可以这样做
DataObject.Entities dataEntities=new DataObject.Entities();
DataObject.Section section = dataEntities.Sections.First(s=>s.Staffs
.Select(ss=>ss.StaffId).Contains(staffId));
有了它,我可以获得与标记匹配的第一节的信息(例如:这里的info-about-section-id=1)
用同样的方法,我试着获取某个特定标记的所有SectionID,比如
List<int> sectionIds = dataEntities.Sections.Where(s => s.Staffs.Where
(ss => ss.StaffId == staffId)).Select(sec=>sec.SectionId);
List sectionIds=dataEntities.Sections.Where(s=>s.staff.Where
(ss=>ss.StaffId==StaffId))。选择(sec=>sec.SectionId);
但它不起作用,有人能帮我吗
这是我知道的标记,我需要得到所有的分区ID
相应的标记
List sectionIds=dataEntities.Sections
.Where(se=>se.Staff.Any(st=>st.StaffId==StaffId))
.Select(se=>se.SectionId)
.ToList();
这是我知道的标记,我需要得到所有的分区ID
相应的标记
List sectionIds=dataEntities.Sections
.Where(se=>se.Staff.Any(st=>st.StaffId==StaffId))
.Select(se=>se.SectionId)
.ToList();
非常感谢Slauma,我从昨晚起就一直在这里闲逛,非常友好的uthanks Allo Slauma,我从昨晚起就一直在这里闲逛,非常友好的u
List<int> sectionIds = dataEntities.Sections
.Where(se => se.Staffs.Any(st => st.StaffId == staffId))
.Select(se => se.SectionId)
.ToList();