[轉貼] LINQ傻瓜教學之二:Left Join 和多字段關聯

2013031409:25
出處:http://blog.csdn.net/avi9111/article/details/4750901

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;