简体   繁体   English

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

[英]How to pull one column from second table in Linq query with join

I have the following linq query that works fine, but I am wanting to pull one column (CompanyId) from context.Emps into the results along with the results from context.BillingProfiles. 我有以下运行良好的linq查询,但是我想从context.Emps中拉出一列(CompanyId)以及context.BillingProfiles的结果。 How would I modify the select (select prof) below to include said column? 我将如何修改下面的选择(选择教授)以包括所述列?

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) && (grp.System == "sysGrp") && (prof.ID == id)
             select prof).Distinct()
            .Select(x => new OpId()
            {
                id = x.ID,                                        
                GroupId = x.GroupID,
                OpId = x.OpID,
                StartDate = x.StartDate,
                EndDate = x.EndDate,
                AddedOn = x.AddedOn,
                AddedBy = x.AddedBy,
                RemovedOn = x.RemovedOn,
                RemovedBy = x.RemovedBy,
                Prodid = x.ProdID,
            });

Thanks 谢谢

Project an anonymous object containing those too: 投影一个也包含这些对象的匿名对象:

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 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM