Kaushal Kaushal - 1 month ago 4x
SQL Question

LINQ join on non equal keys

I need to convert this SQL query into LINQ

FROM Table1 t1
JOIN Table2 t2 ON t1.LogDate >= t2.StartDate AND t1.LogDate <= t2.EndDate

What should be the LINQ for above SQL query?


LINQ only supports join on equal keys, I suggest using cross join. Depending on your query optimizer it may be converted to inner join

from t1 in Table1
from t2 in Table2
where t1.LogDate >= t2.StartDate && t1.LogDate <= t2.EndDate
select new { t1, t2 }