2016-12-15 62 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关联交易。