linq中怎么实现多条件关联的左右连接
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中怎么实现多条件关联的左右连接的更多相关文章
- Jmeter If Controller中设置多个条件用“与”进行连接
"${noteID}"!="NOT FOUND" && "${securitiesId}"!="0P00011FQ ...
- Linq→join中指定多个条件
还是习惯先撸一段SQL * FROM User_Pic P AND P.Guid = R.UserPicGuid ORDER BY PicSize DESC 然后发现Linq中的join不能多条件.. ...
- linq中的contains条件
linq中的contains条件 在sql查询语句中,in 在linq 中用contains,并且contains前面是数组,而后面是列名,如: SELECT distinct BH FROM c ...
- 2.4 LINQ中使用where子句指定筛选条件
本篇讲解的内容有: 使用where筛选过滤LINQ查询 带逻辑的where筛选 多个where筛选子句 [1.使用where筛选过滤LINQ查询] 通常一个LINQ查询不会如前面的示例代码这么简单,经 ...
- TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式
A表字段与B表中的关联,关联条件中一列是随机关联的实现方式 create table test( rsrp string, rsrq string, tkey string, distan strin ...
- linq中如何实现多个条件的联合查询
目前接触处理数据这一块比较多,在处理内存中的数据源的时候我一般使用的是linq,linq使用起来像sql语句一样,用法简单,功能强大. 最近需要实现一个从两个不同的文件读取不同的数据,然后根据这两个数 ...
- Linq中字段数据类型转换问题(Linq to entity,LINQ to Entities 不识别方法"System.String ToString()"问题解决)
1.在工作中碰到这样一个问题: 使用linq时,需要查询两个表,在这两张表中关联字段分别是int,和varchar()也就是string,在linq中对这两个字段进行关联, 如果强制类型转换两个不同类 ...
- C# if中连续几个条件判断
C# if中连续几个条件判断 1.if (条件表达式1 && 条件表达式2) 当条件表达式1为true时 using System; using System.Collections. ...
- Linq中关键字的作用及用法
Linq中关键字的作用及用法 1.All:确定序列中的所有元素是否都满足条件.如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true:否则为 false. Demo: 此示例使用 ...
随机推荐
- linux/Windows系统如何安装PHP-openssl扩展
今天倒腾了半天公司的OA办公系统,原来现在很多的smtp服务器是需要ssl方式加密的,而支持ssl需要php加载openssl扩展.所以本文我们将和大家一起分享如何在linux/Windows系统下安 ...
- 使用 TUN 设备实现一个简单的 UDP 代理隧道
若要实现在 Linux 下的代理程序,方法有很多,比如看着 RFC 1928 来实现一个 socks5 代理并自行设置程序经过 socks5 代理等方式,下文是使用 Linux 提供的 tun/tap ...
- Linux之不得不说的init(Linux启动级别的含义 init 0-6)
init 0:关机: init 1:单用户模式(只root进行维护): init 2:多用户 init 3:完全多用户 init 4:安全模式 init 5:图形化 init 6:重启 可以在/etc ...
- The Moving Points hdu4717
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- The Twin Towers zoj2059 DP
The Twin Towers Time Limit: 2 Seconds Memory Limit: 65536 KB Twin towers we see you standing ta ...
- 石子合并(NOI1995)
石子合并(NOI1995) 时间限制: 1 Sec 内存限制: 128 MB提交: 90 解决: 48[提交][状态][讨论版] 题目描述 在操场上沿一直线排列着 n堆石子.现要将石子有次序地合并 ...
- Win下安装虚拟机(Linux)
**********************win下体验linux**************************************By熟知宇某 一.先说说win10和win8系统下的hyp ...
- ch1-vuejs基础入门(hw v-bind v-if v-for v-on v-model 应用组件简介 小案例)
1 hello world 引入vue.min.js 代码: ----2.0+版本 <div id="test"> {{str}} </div> <s ...
- 吾八哥学Python(四):了解Python基础语法(下)
咱们接着上篇的语法学习,继续了解学习Python基础语法. 数据类型大体上把Python中的数据类型分为如下几类:Number(数字),String(字符串).List(列表).Dictionary( ...
- 微信小程序点击返回顶层实现方法
最近在研究微信小程序,被这个返回顶层给坑了一波,下面贴代码 wxml代码: <scroll-view scroll-y style="height: 1000rpx;" sc ...