linq用lambda表达式 left join 自连接怎么写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linq用lambda表达式 left join 自连接怎么写相关的知识,希望对你有一定的参考价值。

参考技术A .问题解决
通过以上分析,将''改为NULL,问题得到有效解决或者把谓词写到每个子SQL里面。当然,只要是非''的都是可以的,比如' '(空格)。

dingjun123@ORADB> SELECT *
2 FROM (SELECT t1.subobject_name, t1.object_name, t1.object_type
3 FROM t1
4 UNION ALL
5 SELECT NULL, t2.object_name, t2.object_type
6 FROM t2
7 UNION ALL
8 SELECT t3.subobject_name, NULL, t3.object_type FROM t3) t
9 WHERE (t.subobject_name = 'T' OR t.object_name = 'T');

256 rows selected.
Elapsed: 00:00:00.72

Execution Plan
----------------------------------------------------------
Plan hash value: 3324794093
---------------------------------------------------------------------本回答被提问者和网友采纳

Linq 多连接及 left join 实例 记录

var retList = from d in mbExList.Cast<MaterialBaseEx>().ToList()
join c in umcList.Cast<ClassifyBaseEx>().ToList() on d.ClsCode equals c.ClsCode
join b in collectItem.Cast<CollectItem>().ToList() on d.Guid equals b.MatID into temp
join e in mlpList.Cast<MaterialLastPrice>().ToList() on d.MatCode equals e.MatCode into tempxx
from tt in temp.DefaultIfEmpty()
from xx in tempxx.DefaultIfEmpty()
where (d.IsPublish.Equals(true)) || tt != null
select new MaterialPriceCollect
{
Guid = Guid.NewGuid().ToString(),
MatCode = d.MatCode,
//Area = areaRec.Text,
PriceType = 1,
State = 2,
MatName = d.MatName==null?"":d.MatName,
Unit = d.MatUnit == null ? "" : d.MatUnit,
MatType = d.MatModel == null ? "" : d.MatModel,
LastPrice = (xx==null || xx.LastPrice == null) ? 0 : xx.LastPrice,
UserId = "_" + userId + ",",
MatId = d.Guid == null ? "" : d.Guid,
IsFrequently = (int)EumIsFrequently.否,
//ReportTime = DateTime.Now,
Weight = (tt==null ||tt.Weight == null) ? 1 : tt.Weight,
//AreaCode = areaRec.Id,
//PeriodNo = objMat.CurPeriodNo,
};

以上是关于linq用lambda表达式 left join 自连接怎么写的主要内容,如果未能解决你的问题,请参考以下文章

c# Linq left join 多个条件连接查询

Linq.join_lambda知识点

linq left join ,inner join ,crossjoin

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

EF的连表查询Lambda表达式和linq语句(转)

(Linq/Lambda) 使用 2 个 DBContext 连接 2 个或更多表