Chinni Rupa

Chinni Rupa

  • NA
  • 7
  • 425

Trying to Convert SQL to LINQ

Nov 8 2019 4:59 PM
 I am tryign to convert to LINQ
 
WITH test AS (
SELECT DISTINCT
SiteID
FROM dbo.RepresentativeItemMeasurementDailySummary)
SELECT
S.SiteCode
FROM dbo.Sites S
INNER JOIN test X ON X.SiteID = S.SiteID
INNER JOIN dbo.SiteExtends SE ON SE.SiteID = S.SiteID
WHERE SE.StartTime > '0:00'
 
This is what I have tried
 
var sites = (from s in context.RepresentativeItemMeasurementDailySummary
join se in context.Sites on s.SiteID equals se.SiteID
where se.SiteCode == SiteCode
select new { s.SiteID, se.SiteCode }).Distinct();
var workingTimes = (from s in context.Sites
join se in context.SiteExtends on s.SiteID equals se.SiteID
where se.StartTime > TimeSpan.Zero
&& s.SiteCode == SiteCode
select new { se.SiteID, s.SiteCode }).ToList();
var comb = (from t in sites
from t1 in workingTimes
where (t.SiteID == t1.SiteID && t.SiteCode == t1.SiteCode)
select new Sites { SiteID = t.SiteID,SiteCode = t.SiteCode }).ToList();
return comb.Distinct().ToList();
 
 
Can someone help me with this
 
 
Thanks!! 

Answers (2)