0
在我的數據庫上下文類我:在MVC3中如何獲得Linq的模型列表?
Imports System.Data.Entity
Public Class MusicStoreEntities
Inherits DbContext
Public Property Albums As DbSet(Of Album)
Public Property Descriptions As DbSet(Of Description)
End Class
然後,我有這兩個模型,專輯和說明
Public Class Album
Public Property AlbumId As Integer
End Class
Public Class Description
Public Property DescriptionId As Integer
Public Property AlbumId As Integer
End Class
從控制器的行動,我可以得到一個單一的描述信息相冊使用Linq如下:
Dim album_description As Description = db.Descriptions.Single(Function(g) g.AlbumId = id)
但是,如何獲取相冊的說明列表?
Dim album_descriptions As List(Of Description) = db.Descriptions.**???**(Function(g) g.AlbumId = id)
所以有一個1-TO-*'Album'和'Description'之間的關係?你應該在'Album'中添加'Public Property Descriptions'並讓EF爲你做。 –