0

在我的数据库上下文类中,我有:

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)
4

2 回答 2

2
  Dim album_descriptions As List(Of Description) = db.Descriptions.Where(Function(g) g.AlbumId = id).ToList() 

应该这样做

于 2012-11-08T15:38:04.297 回答
1

使用此处.Where()记录的方法。

db.Descriptions.Where(Function(g) g.AlbumId = id).ToList()
于 2012-11-08T15:36:54.900 回答