如何使用join从Linq查询中的第二个表中拉出一列

时间:2017-10-16 19:14:29

标签: c# linq

我有以下linq查询可以正常工作,但我想从context.Emps中将一列(CompanyId)与context.BillingProfiles的结果一起拉入结果。我如何修改下面的select(select prof)以包含所述列?

{
    "error": "some error",
    "result": null
}

由于

1 个答案:

答案 0 :(得分:1)

投射一个包含这些内容的匿名对象:

var query = from prof in context.BillingProfiles
            join emp in context.Emps on prof.ID equals emp.ID
            join grp in context.BillingGroups on prof.GroupID equals grp.GroupID
            where prof.EndDate == null && prof.ID == id && grp.System == "sysGrp"
            select new { prof, emp.CompanyId, grp };