首页 > 代码库 > Linq 多连接及 left join 实例 记录

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 实例 记录