1、左连接
var LeftJoin = from emp in db.UserInfo
join dept in db.UserSub
on emp.UserId equals dept.UserId into zlj
from dept in zlj.DefaultIfEmpty()
select new
{
EmployeeName = emp.UserName
}
2、右连接
var RightJoin = from dept in ListOfDepartment
join employee in ListOfEmployees
on dept.ID equals employee.DeptID into ylj
from employee in ylj.DefaultIfEmpty()
select new
{
};
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, };
4、多字段关联查询
var userListTest = (from a in db.UserInfo
join p in db.UserSub
on new { a.UserId,a.UserName } equals new{p.UserId,p.UserName}//多字段连接查询
select new
{ uid = a.UserId,
un = a.UserName,
gd = a.Gender,
bt = a.Birthday,
po = p.phone,
ea = p.Email
}).ToList();