Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The generated sql includes the following line, where @p4 corresponds to the <code>Blahblahblah=false</code> line in your projection:</p> <pre><code>DECLARE @p4 Int = 0 </code></pre> <p>And the int that is returned from the query can't be converted to a bool. I don't know whether or not this is a linq to sql bug (seems like it), but there is a workaround. Basically you need to drop the <code>Blahblahblah=false</code> from the anonymous type projected, then <code>.ToList()</code> or <code>.ToArray()</code> the result, and finally add the bool field in a linq to objects projection:</p> <pre><code>var one = (from ch in TEST_CHARTs join a in TEST_CHART_SERIES on ch.CHARTID equals a.CHARTID into a_join from cs in a_join.DefaultIfEmpty() join ycols in TEST_QUERY_COLS on new { key1 = cs.YAXIS, key2 = ch.QUERYID } equals new { key1 = ycols.COLNAME, key2 = ycols.QUERYID } where ch.CHARTID == 1 select new { ch.CHARTID, POSITION = 0, ycols.QUERYID, ycols.Otherblah, Blahblahblah = cs.Blahblahblah }).ToList(); var two = (from ch in TEST_CHARTs join xcol in TEST_QUERY_COLS on new { key1 = ch.XAXIS, key2 = ch.QUERYID } equals new { key1 = xcol.COLNAME, key2 = xcol.QUERYID } where ch.CHARTID == 1 select new { ch.CHARTID, POSITION = 0, xcol.QUERYID, xcol.Otherblah }).ToList(); var three = from x in two select new { x.CHARTID, x.POSITION, x.QUERYID, x.Otherblah, Blahblahblah = false }; var four = one.Union(three).Distinct(); </code></pre> <p>Note that this results in two sql queries, not one.</p> <p><strong>EDIT</strong></p> <p>Also, Distinct() can be left out, since union doesn't include duplicates. I should have actually <em>read</em> the code that I copied and pasted!</p>
 

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