2016-12-15 54 views
2

我有一個包含四個表的實體框架模型,我們需要關注的唯一兩個是[AtmAccounts]和[Transactions]。 [AtmAccounts]具有以下屬性:[Id -Primary Key],[AccountNumber],[AccountBalance],[UserId]和[AccTypeId]。事務具有以下內容:[Id-主鍵],[TransAmount],[TransDate],[AtmAccountId - 導航屬性]和[TransTypeId]。通過外鍵從相關表中檢索數據

我想要獲取特定帳戶的交易清單並將它們顯示在屏幕上。爲此,我需要從Transaction表中獲取與存儲在AtmAccounts中的AtmAccountId相對應的所有記錄。我該如何解決這個問題?

+2

'db.Transactions.Where(s => s.AtmAccountId == someAccountId「)'? – Shyju

+0

@JayRoberts會爲您做上述工作嗎? –

回答

0

除非您刪除了關係,否則您的外鍵關係應該已經存在於您的實體模型中。在你的代碼智能感知應該表現出這一點,例如:

var myList = (from x in db.AtmAccounts 
      where x.Id==myspecifiedid 
      select x.Transactions).ToList(); 

應該給你指定的AtmAccount關聯交易。