I have a legacy SQL script that join prob_contact table with other tables by comparing number of days with date range low_amt and high_amt. This work perfectly fine with SQL.
JOIN prob_contact p ON (s.end_date - s.start_date) BETWEEN p.low_amt AND p.high_amt
I want to convert the SQL script to Linq, but I'm having an issue on nullable TimeSpan? Please let me know if there is a solution for this problem.
let d = s.End_date - s.Start_date
Original T-SQL Command (datasource Oracle 12c by Joan Casteel)
SELECT (c.last + ', ' + c.first) AS name, s.start_date, s.end_date, p.con_freq
FROM dbo.criminals c INNER JOIN dbo.sentences s ON c.criminal_id = s.criminal_id
INNER JOIN dbo.prob_officers o ON o.prob_id = s.prob_id
JOIN prob_contact p ON (s.end_date - s.start_date) BETWEEN p.low_amt AND p.high_amt
ORDER BY name, s.start_date;
Linqpad script
var result = from c in Criminals
join s in Sentences on c.Criminal_id equals s.Criminal_id
let d = s.End_date - s.Start_date
from p in Prob_contacts where d < p.Low_amt
orderby c.Last
select new {
name = c.Last + ", " + c.First,
startDate = s.Start_date,
freq = p.Con_freq,
d
};
