以下是我拥有的实体......
Public Class Account
Public Property AccountId As integer
Public Property AccountDescription As String
Public Property Transactions As List(Of Transaction)
End Class
Public Class Transaction
Public Property TransactionId As Integer
Public Property AccountId As Integer
Public Property TransactionDescription As String
End Class
我想说的是,当我执行“db.Account.find(1)”时,它也会加载到具有相应AccountId的所有事务的列表中。我不太确定这是什么类型的关系?无论如何,现在我可以做到
Dim acct As Account = db.Account.Find(1)
acct.Transactions = from ts in db.transactions select ts where ts.AccountId = acct.accountid
但是我知道这不是正确的方法,必须有一种方法将其映射出来,以便实体可以一次性加载所有内容吗?谢谢你的帮助。
答案 0 :(得分:1)
您可以使用db.Account.Include("Transactions").SingleOrDefault(1)
或将交易视为虚拟(我认为它在vb中是可覆盖的)。