How to join 3 tables with lambda expression?

后端 未结 4 1993
借酒劲吻你
借酒劲吻你 2021-01-31 11:47

I have a simple LINQ lambda join query but I want to add a 3rd join with a where clause. How do I go about doing that?

Here\'s my single join query:

var         


        
4条回答
  •  死守一世寂寞
    2021-01-31 12:21

    Just a guess:

    var myList = Companies
        .Join(
            Sectors, 
            comp => comp.Sector_code,
            sect => sect.Sector_code,
            (comp, sect) => new { Company = comp, Sector = sect })
        .Join(
            DistributionSectorIndustry.Where(dsi => dsi.Service == "numerical"), 
            cs => cs.Sector.Sector_code,
            dsi => dsi.Sector_code,
            (cs, dsi) => new { cs.Company, cs.Sector, IndustryCode = dsi.Industry_code })
        .Select(c => new {
            c.Company.Equity_cusip,
            c.Company.Company_name,
            c.Company.Primary_exchange,
            c.Company.Sector_code,
            c.Sector.Description,
            c.IndustryCode
    });
    

提交回复
热议问题