Linq to Sql 左连接查询

 1 var query = from t0 in context.ExpressSendMaster
 2 join t1 in context.Supplier on t0.SupplierCode equals t1.SupplierCode
 3 join t2 in context.ExpressSendPackageRule on t0.AreaId equals t2.Id into t0_join
 4 from t0_t2 in t0_join.DefaultIfEmpty()
 5 where t0.Id == MasterId
 6 select new ExpressPackageOffLineModel
 7 {
 8 PackWeight = t0.Weight,
 9 SupplierCode = t1.SupplierCode,
10 SupplierName = t1.Name,
11 SendDate = t0.SendDate,
12 OneselfNumber = t0.OneselfNumber,
13 Memo = t0.Memo,
14 GroupCheck = t0.AreaCode,
15 GroupName = t0_t2.NumberType == null ? "" : t0_t2.NumberType,
16 GroupId = t0_t2.Id == null ? 0 : t0_t2.Id,
17 LimitWeight = t0_t2.LimitWeight == null ? 0 : t0_t2.LimitWeight
18 };
19
20
21 if (query.Count() <= 0)
22 {
23 model.HasError = true;
24 model.ErrorMessage = "错误提示";
25 return false;
26 }
27
28 model.PackWeight = query.First().PackWeight;
29 model.SupplierCode = query.First().SupplierCode;
30 model.SupplierName = query.First().SupplierName;
31 model.SendDate = query.First().SendDate;
32 model.OneselfNumber = query.First().OneselfNumber;
33 model.GroupName = query.First().GroupName;
34 model.Memo = query.First().Memo;
35 model.GroupCheck = query.First().GroupCheck;
36 model.GroupId = query.First().GroupId;
37 model.LimitWeight = query.First().LimitWeight;

时间: 2024-12-18 18:54:28

Linq to Sql 左连接查询的相关文章

sql左连接查询+右表带有条件的实现

select * from A表 a left join B表 b on a.id=b.a_id and b.字段='/*条件*/' ; 可查出左表所有数据 select * from A表 a left join B表 b on a.id=b.a_id where b.字段='/*条件*/' ; 只能查出部分数据 原文地址:https://www.cnblogs.com/edllixiaoyu/p/11664126.html

SQL左连接、右连接和内连接的简单示例

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录: right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录: inner join(等值连接) 只返回两个表中联结字段相等的行:举例如下: -------------------------------------------- 表A记录如下: aID aNum 1 a20050111 2 a20050112 3 a20050113 4 a20050114 5 a20050115 表B记录

Linq to Sql 多条件查询

Linq To Sql 多条件查询 string proName = this.txtName.Text.Trim();string lowPrice = this.txtLowPrice.Text.Trim();string highPrice = this.txtHighPrice.Text.Trim(); decimal? lowPrice1 = null, highPrice1 = null;if (!string.IsNullOrEmpty(lowPrice)){        low

左连接查询

左连接查询语句 表1 left join 表2 on 条件: 然后where,having,group等语句可以照常使用 以下例子用两次左连接进行匹配 select t1.tname,mres,t2.tname,matime from m left join t as t1 on t1.tid=m.hid left join t as t2 on t2.tid=m.gid; mysql> set names gbk; Query OK, 0 rows affected (0.02 sec) my

EF的左连接查询

在EF中,当在dbset使用join关联多表查询时,连接查询的表如果没有建立相应的外键关系时,EF生成的SQL语句是inner join(内联),对于inner join,有所了解的同学都知道,很多时候这并不是我们的本意,实例如下: var list = from o in context.CTMS_OD_ORDERS join d in context.CTMS_SUP_DOCTOR on o.OWNERDOCID equals d.USERID join e in context.CTMS_

基本sql语句--连接查询

union 联合 union的作用:把两次或多次查询结果合并起来. 典型案例:select good_id,good_name from good where shop_price>5000 or shop_price<20; select good_id,good_name from good where shop_price>5000 union select good_id,good_name from good where shop_price<20; 1.union的要求

多个左连接查询

建表 create table AAAAA0 ( GKNAME VARCHAR2(50), NUM    VARCHAR2(10) ) create table AAAAA1 ( CNAME VARCHAR2(50), NUM0  VARCHAR2(10), NUM1  VARCHAR2(10), NUM2  VARCHAR2(10) ) 问题描述 ORACLE SQL 多列外连接怎么匹配查询? 列出每条船的当前港口名,下一站港口名,终点港口名. 解决 select b0.cname,a0.gk

SQL:左连接,右连接

SELECT ename , dname FROM Emp, Dept WHERE Emp.Deptno(+) = Dept.Deptno 也可以写成: SELECT ename , dname FROM Emp RIGHT JOIN Dept ON Emp.Deptno = Dept.Deptno 此SQL文使用了右连接,即"(+)"所在位置的另一侧为连接的方向,右连接说明等号右侧的所有记录均会被显示,无论其在左侧是否得到匹配,也就是说上例中无论会不会出现某个部门没有一个员工的情况,

mysql left join 左连接查询关联n多张表

eft join 左连接即以左表为基准,显示坐标所有的行,右表与左表关联的数据会显示,不关联的则不显示.关键字为left join on. **基本用法如下: select table a left join table b on a.id = b.ta_id** 注意:1??其中on后面关联的字段应该是同一字段(两表关联的外键) 2??由于以左表为基准,左表一条记录如果对应右表多条记录,那查出的数据中右表的数据也只显示一条,如果要都显示,可以用group_contact()将字段用逗号隔开显示