将内部连接 Linq 查询放入视图模型
Placing Inner Join Linq Query Into View Model
视图模型:
public IEnumerable<Telephone_Search.Models.tbl_users> users;
public IEnumerable<Telephone__Search.Models.tbl_pics> images;
public IEnumerable<Telephone__Search.Models.tbl_locations> branches;
控制器:
public ActionResult Index()
{
var users = from a in db.tbl_users
where a.userid == 6
select a;
var branchjoin = (from e in db.users
join c in db.tbl_locations on e.address equals c.location
where e.userid == 6 && e.emp_address == c.location
select c).ToArray();
return this.View(new ViewModel
{
branches = branchjoin // Error here
users = users,
});
}
如何 c.location
进入 MVC 中的 razor 视图?我遇到的最常见错误是无法从 IQueryable
转换为 System.Generic.Collection
。错误在代码中说明。
将 .ToArray()
替换为 .ToList().AsQueryable()
,这样可以吗?
视图模型:
public IEnumerable<Telephone_Search.Models.tbl_users> users;
public IEnumerable<Telephone__Search.Models.tbl_pics> images;
public IEnumerable<Telephone__Search.Models.tbl_locations> branches;
控制器:
public ActionResult Index()
{
var users = from a in db.tbl_users
where a.userid == 6
select a;
var branchjoin = (from e in db.users
join c in db.tbl_locations on e.address equals c.location
where e.userid == 6 && e.emp_address == c.location
select c).ToArray();
return this.View(new ViewModel
{
branches = branchjoin // Error here
users = users,
});
}
如何 c.location
进入 MVC 中的 razor 视图?我遇到的最常见错误是无法从 IQueryable
转换为 System.Generic.Collection
。错误在代码中说明。
将 .ToArray()
替换为 .ToList().AsQueryable()
,这样可以吗?