Linq to Entities Many to Many Query WPF DataGrid -


i have many many relationship in sql server 2008:

student table (studentid pk, studentname)

course table (courseid pk, coursename)

studentcourse (pure junction table) (studentid, courseid both in composite pk).

in visual studio 2010:

entity model setup properly. have datagrid bound to:

<collectionviewsource x:key="courseviewsource" d:designsource="{d:designinstance my:course, createlist=true}" />"

this allows me set datagrid columnsproperty both tables: coursename , students.studentname.

i need show students in courses in, on same datagrid.

my query is:

    ` var context = new context();       var list = y in context.courses          z in y.students          select y;          datagrid1.itemssource = list;` 

this query returns first student in table student in courses , gets repeated, can't show other students taking same courses , other courses.

question: how can change query using linq entities. have tried many things many days.

thanks in advance.

try include instead, this:

var list = (from y in context.courses.include("students") select y).tolist(); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -