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
};
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 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;
沒有留言:
張貼留言