linq左右连接最重要的是DefaultIfEmpty()这个方法和join之后的表中判断是否( temp != null)null,左右连接其实就是表的位置互换。

1、左连接:

from order in context.vab_OrderGoods.Where(i => i.deletef ==  && i.order_id == orderId && i.input_type == )
join goods in context.mst_Goods.Where(k => k.eigyousyo_id == _eigyousyoId)
on order.goods_id equals goods.goods_id into ogt
from og in ogt.DefaultIfEmpty()
join kind in context.mst_GoodsKind.Where(l => l.deletef == && l.eigyousyo_id == _eigyousyoId)
on og.goods_kind_id equals kind.goods_kind_id into tempTable
from temp in tempTable.DefaultIfEmpty() select new FA2_GoodsInfoModel
{
seq_id = order.seq_id,
order_id = order.order_id,
goods_id = order.goods_id,
deletef = order.deletef,
goods_count = order.goods_count,
goods_name = og.goods_name,
goods_name_kana = og.goods_name_kana,
goods_weight = og.goods_weight,
input_type = order.input_type,
sub_total_goods_weight = order.sub_total_goods_weight,
goods_kind_id = temp != null ? temp.goods_kind_id : ,
goods_kind_name = temp != null ? temp.goods_kind_name : string.Empty
}

2、右连接:

from goods in context.mst_Goods.Where(k => k.eigyousyo_id == _eigyousyoId)

join order in context.vab_OrderGoods.Where(i => i.deletef ==  && i.order_id == orderId && i.input_type == )

on goods.goods_id equals order.goods_id into ogt
from og in ogt.DefaultIfEmpty()
join kind in context.mst_GoodsKind.Where(l => l.deletef == && l.eigyousyo_id == _eigyousyoId)
on og.goods_kind_id equals kind.goods_kind_id into tempTable
from temp in tempTable.DefaultIfEmpty() select new FA2_GoodsInfoModel
{
seq_id = order.seq_id,
order_id = order.order_id,
goods_id = order.goods_id,
deletef = order.deletef,
goods_count = order.goods_count,
goods_name = og.goods_name,
goods_name_kana = og.goods_name_kana,
goods_weight = og.goods_weight,
input_type = order.input_type,
sub_total_goods_weight = order.sub_total_goods_weight,
goods_kind_id = temp != null ? temp.goods_kind_id : ,
goods_kind_name = temp != null ? temp.goods_kind_name : string.Empty
}

linq中怎么实现多条件关联的左右连接的更多相关文章

  1. Jmeter If Controller中设置多个条件用“与”进行连接

    "${noteID}"!="NOT FOUND" && "${securitiesId}"!="0P00011FQ ...

  2. Linq→join中指定多个条件

    还是习惯先撸一段SQL * FROM User_Pic P AND P.Guid = R.UserPicGuid ORDER BY PicSize DESC 然后发现Linq中的join不能多条件.. ...

  3. linq中的contains条件

    linq中的contains条件   在sql查询语句中,in 在linq 中用contains,并且contains前面是数组,而后面是列名,如: SELECT distinct BH FROM c ...

  4. 2.4 LINQ中使用where子句指定筛选条件

    本篇讲解的内容有: 使用where筛选过滤LINQ查询 带逻辑的where筛选 多个where筛选子句 [1.使用where筛选过滤LINQ查询] 通常一个LINQ查询不会如前面的示例代码这么简单,经 ...

  5. TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式

    A表字段与B表中的关联,关联条件中一列是随机关联的实现方式 create table test( rsrp string, rsrq string, tkey string, distan strin ...

  6. linq中如何实现多个条件的联合查询

    目前接触处理数据这一块比较多,在处理内存中的数据源的时候我一般使用的是linq,linq使用起来像sql语句一样,用法简单,功能强大. 最近需要实现一个从两个不同的文件读取不同的数据,然后根据这两个数 ...

  7. Linq中字段数据类型转换问题(Linq to entity,LINQ to Entities 不识别方法"System.String ToString()"问题解决)

    1.在工作中碰到这样一个问题: 使用linq时,需要查询两个表,在这两张表中关联字段分别是int,和varchar()也就是string,在linq中对这两个字段进行关联, 如果强制类型转换两个不同类 ...

  8. C# if中连续几个条件判断

    C# if中连续几个条件判断 1.if (条件表达式1 && 条件表达式2) 当条件表达式1为true时 using System; using System.Collections. ...

  9. Linq中关键字的作用及用法

    Linq中关键字的作用及用法 1.All:确定序列中的所有元素是否都满足条件.如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true:否则为 false. Demo: 此示例使用 ...

随机推荐

  1. JS数字金额转换为货币汉字形式

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  2. D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)

    D. Mysterious Present time limit per test 2 seconds memory limit per test 64 megabytes input standar ...

  3. Java面向对象 线程技术--上篇

     Java面向对象   线程 知识概要:                   (1)线程与进程 (2)自定义线程的语法结构 (3)多线程概念理解 (4)多线程状态图 (5)多线程--卖票 (6)同 ...

  4. YYModel学习总结YYClassInfo(1)

    OC的run-time 机制,简直像是网络上的猫! 我在开发中很少用到,但是作为iOS开发 人家肯定会问这个东西,所以深入的学习了下. 对于 run-time的入手,YYModel的学习,简直让人美滋 ...

  5. Jquery 使用Ajax获取后台返回的Json数据后,页面处理

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 《深入浅出WPF》笔记——绘画与动画

    <深入浅出WPF>笔记——绘画与动画   本篇将记录一下如何在WPF中绘画和设计动画,这方面一直都不是VS的强项,然而它有一套利器Blend:这方面也不是我的优势,幸好我有博客园,能记录一 ...

  7. firewalld 操作实践

    1.firewalld 从名称上看,模仿的是硬件防火墙的概念,zone. 所有的接口都必须属于某个zone . 在zone内配置规则. 2.  常用的方法是 增加对一个tcp或者udp端口号的允许通过 ...

  8. Javascript 面向对象编程—封装

      前  言 Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有class(类) ...

  9. 如何结合场景利用block进行回调

    我们在开发中常常会用到函数回调,你可以用通知来替代回调,但是大多数时候回调是比通知方便的,所以何乐而不为呢?如果你不知道回调使用的场景,我们来假设一下: 1.我现在玩手机 2.突然手机没有电了 3.我 ...

  10. java自动化测试-http请求结合抓包工具实际应用

    继上文我编写了java的get请求与post请求之后,我现在开始写一下实际操作 很多人有疑问,接口测试的代码是哪里来的,怎么来的呢?看得见吗?我来做一个简单的演示 我们这里简单介绍一下抓包工具,对于一 ...