Answers for "linq query join two tables c#"

SQL
0

join two tables in linq c#inner join

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();
Posted by: Guest on April-13-2021
0

how to write join query in linq c#

var locationInfo = entities.TagTemperatures    // your starting point - table in the "from" statement
            .Join(entities.ReverseGeoFenceAddresses, // the source table of the inner join
               tt => tt.TagTemperatureId,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
               rg => rg.TagTemperatureId,   // Select the foreign key (the second part of the "on" clause)
               (tt, rg) => new { TT = tt, RG = rg }) // selection
            .Where(TTandRG => TTandRG.TT.TagId == tag.TagId && TTandRG.TT.SampleTime > StartDate && TTandRG.TT.SampleTime < EndDate)
            .Select(X => new { X.TT.Latitude, X.TT.Longitude, X.TT.SampleTime, X.TT.TemperatureCelsius, X.TT.isAlert, X.TT.isYAlert, X.RG.FullAddress }).ToList();    // where statement
Posted by: Guest on July-22-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language