【发布时间】:2012-03-25 12:39:37
【问题描述】:
我在 SQL Server 2008 中有一个多对多关系:
学生表(StudentID 为 PK,StudentName)
课程表(CourseID 为 PK,CourseName)
StudentCourse(纯连接表)(StudentID、CourseID 都在复合 PK 中)。
在 Visual Studio 2010 中:
实体模型设置正确。 我有一个 DataGrid 绑定到:
<CollectionViewSource x:Key="CourseViewSource" d:DesignSource="{d:DesignInstance my:Course, CreateList=True}" />"
这允许我将 dataGrid 列属性设置为两个表:CourseName 和 Student.StudentName。
我需要在同一个数据网格上显示他们所在的所有课程中的所有学生。
我的查询是:
` var context = new context();
var List = from y in context.Courses
from z in y.Students
select y;
dataGrid1.ItemsSource = List;`
此查询返回所有课程表 Student 中的第一个学生并重复,但我无法显示正在学习相同课程和其他课程的其他学生。
问题: 如何使用 linq 将查询更改为实体。我已经尝试了很多天。
提前致谢。
【问题讨论】:
标签: datagrid linq-to-entities many-to-many