LINQ延迟执行并在左外连接中返回null

时间:2014-05-07 07:14:06

标签: c# entity-framework orm entity-framework-4.1

我有两个问题,请参阅以下代码:

var table1 = from a in test1
             join b in test2 on a.column1 equals b.column1 into jo
             from jb in jo.DefaultIfEmpty()
             select new
             {
                col1 = jb == null ? <question 1> : jb.column1
             }

var table2 = from a in test3
             join b in test4 on a.column1 equals b.column1 into jo
             from jb in jo.DefaultIfEmpty()
             select new
             {
                col1 = jb == null ? <question 1> : jb.column1
             }

var table3 = from x in table1
             join y in table2 on x.col1 equals y.col1 into jo
             from jb in jo.DefaultIfEmpty()
             {
                  col1 = jb == null ? <question 1> : jb.col1
             }

var table4 = from z in table1.Concat(table2)
             select new TheTables()
             {
                 column1 = x.col1
             }

第一个问题:是否可以设置“null”值而不是在语句中放置默认值?我已经尝试“col1 = jb == null? null :jb.column1”但它会引发异常:

The argument to DbIsNullExpression must refer to a primitive, enumeration or reference type.

第二个问题:从我上面给出的代码中,当我执行“table4.List()”时,这将查询数据库作为组合语句,或者它将查询table1,然后查询table2,然后将其作为table3加入内存中?

0 个答案:

没有答案