Skip to content

Instantly share code, notes, and snippets.

@phatty
Created July 11, 2013 03:47
Show Gist options
  • Save phatty/5972390 to your computer and use it in GitHub Desktop.
Save phatty/5972390 to your computer and use it in GitHub Desktop.
Left join once in for all
var Context = new CSPRedemptionEntities();
var List = from cp in Context.CouponPools
join cb in Context.CouponBatches
on new { CouponBatch_id = cp.CouponBatch_id } equals
new { CouponBatch_id = cb.id }
join m in Context.Members
on new { RedeempBy_id = cp.RedeemBy.Value } equals
new { RedeempBy_id = m.id} into MemberLeft
from x in MemberLeft.DefaultIfEmpty()
where cp.CouponBatch_id == CouponBatch_id && cp.Campaign_id == Campaign_id
orderby cp.Seq
select new CouponDTO {
id =cp.id ,
Issuer_id =cb.Campaign.Issuer_id ,
Campaign_id =cp.Campaign_id ,
Campaign_name =cb.Campaign.Name ,
CouponBatch_id =cp.CouponBatch_id ,
Keyid =cp.Keyid ,
Lot =cp.Lot ,
Seq =cp.Seq ,
Check_digit =cp.Check_digit ,
Generated_id =cp.Generated_id ,
SerialNo =cp.SerialNo ,
IsMarketed =cp.IsMarketed ,
RedeemFlag =cp.RedeemFlag ,
Reward_id =cp.Reward_id ,
CreateDate =cp.CreateDate ,
CreateTime =cp.CreateTime ,
CreateBy =cp.CreateBy ,
RedeemDate =cp.RedeemDate ,
RedeemTime =cp.RedeemTime ,
RedeemBy =cp.RedeemBy ,
Member_name =x.Name == null ? "" : x.Name ,
PointPerCoupon =cb.PointPerCoupon
};
return List.ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment