linq的左连接右连接内连接用法

1、左连接:

var LeftJoin = from i in table1
join j in table2
on i.id equals j.id into table3
from j in table3 .DefaultIfEmpty()
select new                        
{
EmployeeName = i.Name,
DepartmentName = j!= null ? j.Name : null         
};

2、右连接://好像一样

var RightJoin = from i in table1
join j in table2
on i.ID equals j.id into table3
from j in table3.DefaultIfEmpty()
select new                          
{
EmployeeName = j!= null ? j.Name : null,
DepartmentName = i.Name
};

3、内连接:

 var query = from t in entitiy.TB_GCGL_ADA_USER
                 join p in entitiy.TB_GCGL_ZY_ZYK
                 on t.ETPRS_CODE equals p.ETPRS_CODE

                 select new TB_USER_ZYK
                 {
                    USER_ID = t.USER_ID,
                    USER_NAME = t.USER_NAME,
                    USER_PASSWORD = t.USER_PASSWORD,

                 };

你可能感兴趣的:(LINQ)