Many to many relation linq query in EF

允我心安 提交于 2019-12-02 13:59:00

Given that this is EF and your latest clarification you should have a Courses navigation property on your Student entity and a Students navigation on your Course entity that would allow you to do the following:

var students =  db.Students
                  .Single(x=> x.Id == 1)
                  .Courses.SelectMany(c=> c.Students)
                  .Distinct();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!