日期:2014-05-20  浏览次数:20828 次

请教一个关于Linq to Entity查询跨多个表的查询问题
我的表结构如下:
客户表 
customer
ID(key)
name

账户表
accounts
ID(key)
balance

客户-账户
customer2accounts
ID(key)
customerID
accountsID

我现在想要通过传入客户id,检索出账户,也就是:

public ActionResult ShowAccount (id)
{
  var acc= db.account.Where(a=>a.customer2accounts ???点不出来 )

   
  return View(acc);
}

模型视图使用强类型,请问用linq to entity应该如何通过customer的id查询accounts?





------解决方案--------------------
应该用join呀。customer表除非你要用户名否则可以不关联

var query = (from a in customer2accounts
join b in accounts on a.accountsID equals b.ID
where a.customerID == 传入的id
select b).ToList();
------解决方案--------------------
探讨

我的程序是MVC3,join不出来啊。

提示join找不到。