我有4张桌子:
用户:
公司:
出发:
组:
我使用Entity Framework,如何获取用户信息:
像这样:
var va = from vx in dbContex.User
join vy in dbContext.Company
on vx.CompanyId equals vy.Company_id
into a
from b in a
select new {
vx.User_id,
vx.User_Name,
CompanyName = b.Company_Name
};
答案 0 :(得分:0)
一种解决方案可能是:
var detailedUserInformations = (from u in dbContext.User
join c in dbContext.Company on u.Company_id equals c.Company_id
join d in dbContext.Depart on u.Depart_id equals d.Depart_id
join g in dbContext.Group on u.Group_id equals d.Group_id
select new
{
UserId = u.User_id,
UserName = u.User_Name
CompanyName = c.Company_id,
DepartName = d.Depart_Name,
GroupName = g.Group_Name
}).ToArray();
在投射(.Distinct()
)您的选择之前,您必须检查.ToArray()
是否有意义。