我有一个首先使用 EF 4 代码构建的数据库,这里有两个模型:
Public Class HvacAudit
Public Property HvacAuditID As Integer
Public Overridable Property HvacAuditPictures As IEnumerable(Of HvacAuditPicture)
... other properties
End Class
Public Class HvacAuditPicture
Public Property HvacAuditPictureID As Integer
Public Property HvacAuditID As Integer
Public Overridable Property HvacAudit As HvacAudit
... other properties
End Class
当我从数据库中提取我的 HvacAudit 记录时,它们没有 HvacAuditPictures!即使我直接拉图片,它们也在那里。考虑
context.HvacAudits.Where(Function(hva) hva.HvacAuditID = 1).HvacAuditPictures Is Nothing 'evaluates true
context.HvacAuditPictures.Where(Function(p) p.HvacAuditID = 1).Count() 'is currently 20
这是我的上下文类:
Public Class EfContext
Inherits DbContext
Implements IDataSource
Public Property HvacAudits As IDbSet(Of HvacAudit) Implements IDataSource.HvacAudits
Public Property Vendors As IDbSet(Of Vendor) Implements IDataSource.Vendors
Public Property HvacAuditPictures As IDbSet(Of HvacAuditPicture) Implements IDataSource.HvacAuditPictures
Public Property Sites As IDbSet(Of Site)
Public Property Markets As IDbSet(Of Market)
Public Sub SaveChanges1() Implements Domain.DataSource.IDataSource.SaveChanges
SaveChanges()
End Sub
End Class