Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert SQL query (with outer join and datediff) to LINQ
    primarykey
    data
    text
    <p>I have this SQL query that needs to be converted to LINQ.I am new to LINQ and the outer join makes it more difficult for me to convert this query into LINQ.</p> <pre><code>select distinct ls.crew, sd.ambulance, case_number from log_sheet ls left outer join shift_detail sd on ls.crew = sd.crew and sd.time_on between dateadd(d,-1,'2013-05-30 21:48:04.000') and '2013-05-30 21:48:04.000' and (sd.time_off &gt; '2013-05-30 21:48:04.000' or sd.time_off is null) where ls.time_out between dateadd(d,-1,'2013-05-30 21:48:04.000') and '2013-05-30 21:48:04.000' and ('2013-05-30 21:48:04.000' &lt;= ls.time_clear or ls.time_clear is null) and (sd.ambulance = 58 or ls.crew = null) union all select distinct ls.crew, sd.ambulance, case_number from log_hist ls left outer join shift_detail sd on ls.crew = sd.crew and sd.time_on between dateadd(d,-1,'2013-05-30 21:48:04.000') and '2013-05-30 21:48:04.000' and (sd.time_off &gt; '2013-05-30 21:48:04.000' or sd.time_off is null) where ls.time_out between dateadd(d,-1,'2013-05-30 21:48:04.000') and '2013-05-30 21:48:04.000' and ('2013-05-30 21:48:04.000' &lt;= ls.time_clear or ls.time_clear is null) and (sd.ambulance = 58 or ls.crew = null) </code></pre> <p>Can someone please help? My failed attempt looks like this:</p> <pre><code>var shiftDetail = _dispatchRepository.FindQueryable&lt;Domain.Model.ShiftDetail&gt;(); var logsheet = _repository.FindQueryable&lt;Domain.Model.LogSheet&gt;() .Where(ls =&gt; ((ls.time_out &gt;= SqlFunctions.DateAdd("dd", -1, criteria.MRxIncident_Timestamp)) &amp;&amp; (ls.time_out &lt;= criteria.MRxIncident_Timestamp)) &amp;&amp; (criteria.MRxIncident_Timestamp &lt;= ls.time_clear || ls.time_clear == null) &amp;&amp; (ls.crew==null)); var shiftDetailQuery = from l in logsheet join sd in shiftDetail on l.crew equals sd.crewID into LeftJoin from sd in LeftJoin.DefaultIfEmpty() select new MRxCaseSearchResults { CaseNumber = l.case_number, Crew = l.crew, Ambulance = sd.ambulance, OfficerNo = sd.officer_no }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload