score:3

Accepted answer

the generated sql includes the following line, where @p4 corresponds to the blahblahblah=false line in your projection:

declare @p4 int = 0

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 blahblahblah=false from the anonymous type projected, then .tolist() or .toarray() the result, and finally add the bool field in a linq to objects projection:

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();

note that this results in two sql queries, not one.

edit

also, distinct() can be left out, since union doesn't include duplicates. i should have actually read the code that i copied and pasted!


Related Query

More Query from same tag