LINQ傻瓜教学之二:Left Join 和多字段关联

Left Join:(关键是用into tbGod ,然后 tbGod.DefaultIfEmpty)

 

var trxs = from trx in dc.DailyExpense_exp
                       join god in dc.Goods_god on trx.exp_iGoodsID equals god.god_iID into tbGod
                       from gods in tbGod.DefaultIfEmpty()
                       select new
                       {
                           trx.exp_lValue
                           ,
                           trx.exp_cRemark
                           ,
                           trx.exp_dDate
                           ,
                           gods.god_cName
                       };

 

 

多字段关联:

 

var trxJoin = from trx in dc.DailyExpense_exp
                          join god in dc.Goods_god on new { ID = trx.exp_iGoodsID, Remark = trx.exp_cRemark } equals new { ID = god.god_iID, Remark = "AB" }
                      select trx;

 

 

 

你可能感兴趣的:(JOIN,equals,LINQ)