1、左连接:

var LeftJoin = from emp in ListOfEmployees
join dept in ListOfDepartment
on emp.DeptID equals dept.ID into JoinedEmpDept
from dept in JoinedEmpDept.DefaultIfEmpty()
select new 
{
EmployeeName = emp.Name,
DepartmentName = dept != null ? dept.Name : null 
};

如果想实现右连接,就把两个表换一下位置。

2、右连接:

var RightJoin = from dept in ListOfDepartment
join employee in ListOfEmployees
on dept.ID equals employee.DeptID into joinDeptEmp
from employee in joinDeptEmp.DefaultIfEmpty()
select new 
{
EmployeeName = employee != null ? employee.Name : null,
DepartmentName = dept.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,

};

 

 

左链接或右链接,使用DefaultIfEmpty()语法,采用些语法前需要用到into语法

linq实现左连接的更多相关文章

  1. Linq实现左连接、右连接

    --一本错误的记录 insert into Book values('错误时怎样练成的',111)   --左连接 select s.name,b.name from student as s lef ...

  2. Lambda方式左连接有Linq方式左连接

    网上查到的直接使用Join+DefaultIfEmpty的方式是错误的,实际生成SQL是两表先内联接,然后再LEFT JOIN.经过查证,参考资料,最终得到如下两种方式的左连接写法: public v ...

  3. LINQ的左连接、右连接、内连接

    .左连接: var LeftJoin = from emp in ListOfEmployees join dept in ListOfDepartment on emp.DeptID equals ...

  4. linq 之左连接

    List<ArticleModel> articleList = articleRepository.GetAllArticle(); List<UsersModel> use ...

  5. LINQ的左连接、右连接、内连接和Lamda表达式实现Left join

    1.左连接: var LeftJoin = from t1 in l1join t2 in l2on t1.ID equals t2.ID into Joinedt12from t3 in Joine ...

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

    1.左连接: var LeftJoin = from e in ListOfEmployees join d in ListOfDepartment on e.DeptID equals d.ID i ...

  7. linq之左连接 + group by

    var list = from item in (from s in _sysBll.GetList(s => s.ParamID == "TraSchType" & ...

  8. linq join 左连接 leftjoin 多个on条件 where 条件

    var haveChange = from newScore in newScoreList join oldScore in oldScoreList on new{newScore.ExamId, ...

  9. Linq Left Join;linq左连接 (转载)

    来源 https://www.cnblogs.com/xinjian/archive/2010/11/17/1879959.html 准备一些测试数据,如下: use Test Create tabl ...

随机推荐

  1. How Android Draws Views

    https://developer.android.com/guide/topics/ui/how-android-draws.html

  2. 2016-1-6第一个完整APP 私人通讯录的实现 2:增加提示用户的提示框,监听文本框

    一:在登录时弹出提示用户的提示框: 1.使用第三方框架. 2.在登陆按钮点击事件中增加如下代码: - (IBAction)loginBtnClicked { NSString *acount = se ...

  3. yii2 ArrayHelper map 使用

    <不喜勿喷> 引用类 use yii\helpers\ArrayHelper; 源码中修改(尽量不要修改,可以研究下不修改的方式) 源码路径 查看数据 视图层 实现效果

  4. How to set up a basic working Appium test environment

    Appium is a test framework targeting devices; although it is very handy and powerful, it is not so s ...

  5. iOS:测试机添加

    一,首先打开开发者首页:https://developer.apple.com/,点击Member Center二,点击certificates,Identifiers & Profiles三 ...

  6. 夜黑风高的夜晚用SQL语句做了一些想做的事·······

         IT这条漫漫长路注定是孤独的,陪伴我们的只有那些不知冷暖的代码语句和被手指敲打的磨掉了键上的标识的键盘. 之所以可以继续坚持下去,是因为心中有一份永不熄灭的激情. 成功的路上让我们为自己带盐 ...

  7. bold, big, blink

  8. mysql explain用法和结果的含义(转)

    重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...

  9. codevs 2216 线段树 两种更新方式的冲突

    题目描述 Description “神州“载人飞船的发射成功让小可可非常激动,他立志长大后要成为一名宇航员假期一始,他就报名参加了“小小宇航员夏令营”,在这里小可可不仅学到了丰富的宇航知识,还参与解决 ...

  10. 图像处理之face morphing

    以前在论坛.微博经常看到一张脸,五官长得像A,脸型似乎又是B,觉得很有意思. 比如像这张图片.这张图片应该是网友用Photoshop完成的,他们取了郭大爷的五官,放在金元帅的脸上,在把边缘处理平滑. ...