Linq 多连接及 left join 实例 记录
Posted 三瑞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 多连接及 left join 实例 记录的主要内容,如果未能解决你的问题,请参考以下文章
Linq2Sql:即使返回单个记录,也始终执行 LEFT JOIN
LINQ的左连接右连接内连接和Lamda表达式实现Left join