What is the syntax for an inner join in LINQ to SQL?

后端 未结 19 1645
感情败类
感情败类 2020-11-22 04:25

I\'m writing a LINQ to SQL statement, and I\'m after the standard syntax for a normal inner join with an ON clause in C#.

How do you represent the follo

19条回答
  •  灰色年华
    2020-11-22 05:11

    var results = from c in db.Companies
                  join cn in db.Countries on c.CountryID equals cn.ID
                  join ct in db.Cities on c.CityID equals ct.ID
                  join sect in db.Sectors on c.SectorID equals sect.ID
                  where (c.CountryID == cn.ID) && (c.CityID == ct.ID) && (c.SectorID == company.SectorID) && (company.SectorID == sect.ID)
                  select new { country = cn.Name, city = ct.Name, c.ID, c.Name, c.Address1, c.Address2, c.Address3, c.CountryID, c.CityID, c.Region, c.PostCode, c.Telephone, c.Website, c.SectorID, Status = (ContactStatus)c.StatusID, sector = sect.Name };
    
    
    return results.ToList();
    

提交回复
热议问题