Sql 通过外键从相关表检索数据
我有一个包含四个表的实体框架模型,这里我们只需要关注[AtmAccounts]和[Transactions]。[AtmAccounts]具有以下属性:[Id-主键]、[AccountNumber]、[AccountBalance]、[UserId]和[AccTypeId]。事务具有以下内容:[Id-主键],[TransAmount],[TransDate],[AtmAccountId-导航属性]和[TransTypeId]Sql 通过外键从相关表检索数据,sql,asp.net-mvc,entity-framework,Sql,Asp.net Mvc,Entity Framework,我有一个包含四个表的实体框架模型,这里我们只需要关注[AtmAccounts]和[Transactions]。[AtmAccounts]具有以下属性:[Id-主键]、[AccountNumber]、[AccountBalance]、[UserId]和[AccTypeId]。事务具有以下内容:[Id-主键],[TransAmount],[TransDate],[AtmAccountId-导航属性]和[TransTypeId] 我想,得到一个特定帐户的交易列表,并在屏幕上显示它们。为此,我需要从Tr
我想,得到一个特定帐户的交易列表,并在屏幕上显示它们。为此,我需要从Transactions表中获取与存储在AtmAccounts中的AtmAccountId对应的所有记录。如何处理此问题?除非删除关系,否则您的外键关系应该已经存在于实体模型中。在您的代码中,Intellisense应该显示这一点,例如:
var myList = (from x in db.AtmAccounts
where x.Id==myspecifiedid
select x.Transactions).ToList();
应为您提供指定AtmAccount的关联事务。
db.transactions.Where(s=>s.AtmAccountId==someAccountId”)
?@JayRoberts是否为您执行上述操作?