.net Linq里的多表关联查询

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

  • 2
    点赞
  • 3
    收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值