如何在linq c#中加入select union?

时间:2014-11-25 19:51:29

标签: c# linq entity-framework

我对此查询有问题,我需要获取主表mod_solicitud(x),ren_solicitud(y)的所有结果,这些表与其他表有关但不是主表的所有记录都存在于相关表,所以应用内连接,一些数据丢失,如何在linq中应用左连接来获取这些数据或其他一些允许获取所有数据表的技术?

示例:

master tables:
table x,
table y

table a,
table b
var resultado =
    ((from x in "table x"
        join a in "table a" on a.id equals x.id
        select new
        {
            a.id,
            a.name,
            x.pp
        }).union(from y in "table y"
                join b in "table b" on b.id equals y.id
                select new
                {
                    b.id,
                    b.name,
                    x.ww
                })
    );

1 个答案:

答案 0 :(得分:0)

左外连接样本。

var sample= (from e in table1
             join d in table2 on e.column equals d.column into ej
             from d in ej.DefaultIfEmpty()
             select new {e.column , e.column , d.column });
相关问题