问题描述
这个问题在stackoverflow上已经问过好几次了,我已经读了至少六个,但是我无法理解一个简单的多对多linq join查询.这是我的数据库EDMX
this question has been asked several times on stackoverflow, and I have read through atleast half a dozen of those, but I can't get my head around a simple many to many linq join query. This is my database EDMX
我只是想用学生名单以及每个学生的科目填充WPF数据网格.
I'm simply trying to populate a WPF datagrid with the list of students, along with each student's subjects.
现在我知道我们可以简单地使用导航属性,而不是进行联接,但是我一直无法获得正确的结果
Now I know we can simply use navigation properties , instead of doing a join, but I have been unable to get the right result
像这样的(C#/VB.net)查询
so a ( either C#/VB.net )query like
var listOfStudents= // get a list with all students , along with each student's subjects
感谢您的任何帮助,它是如此简单的查询,但我有点受阻
Thank you for any help, its such a simple query but I'm kind of stuck
推荐答案
var listOfStudents = db.Student.Select(x => new { Id = x.Id, Name = x.StudentName, Subjects = x.StudentsSubjects.Select(y => y.Subject) });
这篇关于如何进行Linq多对多联接,无论是否具有导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!