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. hdu 2057

      PS:一开始我画蛇添足的用字符串来做....超麻烦...贴个我做的.. 代码: #include "stdio.h" #include "string.h" ...

  2. Android ListView ListActivity PreferenceActivity背景变黑的问题ZT

    Android ListView ListActivity PreferenceActivity背景变黑的问题 ListView在滚动时背景会变暗甚至变黑,这个要从Listview的效果说起,默认的L ...

  3. Reason we use Camel

    Camel is mainly for integration purpose, in our project we also use it inside the single component t ...

  4. iOS 难题解决日志------2层控制器 上面的控制器显示透明

     f ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { nextVC.modalPresentationStyle=U ...

  5. 解决CSS小于12px的文字在谷歌浏览器显示问题

    做前端设计的人经常要接触CSS方面的问题,估计有不少人会遇到Chrome谷歌浏览器中CSS设置字体小于12px显示不正常,强创网络在做magento模板过程中就遇到了,起初以为是自己写的CSS的问题, ...

  6. C语言--- 字符串数组 、 预处理器和预处理指令 、 多文件编程 、 结构体

    1 输入一个姓名,判断是否是五虎上将. 1.1 问题 本案例需要使用交互的方式判断:用户从控制台输入一个名字,由程序判断该名字是否在五虎上将的名单中.五虎上将的名单是:GuanYu.ZhangFei. ...

  7. invoke Javascript from C# code

    http://justyouraveragegeek.com/blog/index.php/2010/03/winforms-with-a-webbrowsercontrol-fun-with-obj ...

  8. c++ encode decode

    std::string UrlEncode(const std::string& szToEncode) { std::string src = szToEncode; char hex[] ...

  9. python报错

    报错1 UnboundLocalError: local variable 'x' referenced before assignment 定义了一个全局参数,但是在函数中直接改变参数值,就会报这个 ...

  10. Codeforces Round #301 (Div. 2) B. School Marks

    其实是很水的一道bfs题,昨晚比赛的时候没看清题意,漏了一个条件. #include<cstdio> #include<cstring> #include<iostrea ...