首页 > 代码库 > LINQ 左右连接

LINQ 左右连接

LINQ 左右连接:DefaultIfEmpty()

技术分享
incomeList = (from p in db.Incomes                              join m in db.Items                              on p.ItemID equals m.ID into tempResult                              from m in tempResult.DefaultIfEmpty()                              select new IncomeItem                              {                                  ID = p.ID,                                  ItemID = p.ItemID,                                  IncomeMoney = p.IncomeMoney,                                  CreateTime = p.CreateTime,                                  UpdateTime = p.UpdateTime,                                  ItemCode = m.ItemCode,                                  ItemName = m.ItemName                              }).ToList();
View Code

 

LINQ 左右连接