How to do Multiple joins in EF, and load datagrid, using VB
I'm trying to load a grid using EF objects.
select * from
[session] inner join [sessionrep] on [session].ID = [sessionrep].repid
inner join [group] on [group].id = [session].groupid
where [sessionrep].repid = x
I created a partial class and added the properties I wanted to display in the grid in there:
Partial Public Class SessionRep
Public ReadOnly Property Name() As String
Get Return Session.Name
End Get
End Property
....
End Class
I tried doing th开发者_StackOverflow社区is, but it's only loading the table's Active field, the other fields are blank, although the number of rows appear right.
grdSessions.DataSource = db.SessionReps.Include("Session").Include("Session.Group").Include("Session.Group.Program").Where(Function(r) r.RepID = repID).ToList()
What am I doing wrong ? Thanks.
No need for partial classes.
Dim query =
From s In db.Sessions
From d In db.SessionReps
Where s.ID = d.RepID And d.RepID = repID
Select s
grdSessions.DataSource = query.ToList()
grdSessions.DataBind()
精彩评论