Kaushal Kaushal - 1 year ago 86
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?

Answer Source

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 }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download