拉姆达表达式的一些备忘

1、左外连接

 

private  string qtr, rpt;
private List<CommitDetail> _cdList;
private List<CommitDetailExt> _cdextList;
         private List<HddProgramCutoffLeadSetup> _hpclsList;

private  void loadData( string qtr,  string rpt)
        {
             using (DBConn db =  new DBConn())
            {
                 this._cdList = db.CommitDetail.Where(p => p.Deleted ==  false && p.rpt_label ==  this.rpt && p.QTR ==  this.qtr).ToList();
                 this._hpclsList = db.HddProgramCutoffLeadSetup.Where(p => p.Deleted ==  false).ToList();
                 this._ludayList = db.LU_DAY.ToList();
                 this._luweekList = db.LU_WEEK.ToList();
            }

            _cdextList =  this._cdList
                .SelectMany(x =>  this._hpclsList.Where(y => y.Capacity == x.CAPACITY && y.Program == x.NATIVE_ALT_FAMILY).DefaultIfEmpty(),
                    (x, y) =>  new CommitDetailExt {
                        CAPACITY = x.CAPACITY,
                        Commit_QTY = x.Commit_QTY,
                        ConcurrencyMark = x.ConcurrencyMark,
                        CreatedAt = x.CreatedAt,
                        CreatedUserId = x.CreatedUserId,
                        CUSTOMER_CODE = x.CUSTOMER_CODE,
                        Deleted = x.Deleted,
                        DEST_FAC = x.DEST_FAC,
                        FACTORY = x.FACTORY,
                        FMONTH = x.FMONTH,
                        FORM_FACTOR = x.FORM_FACTOR,
                        HEAD_COUNT = x.HEAD_COUNT,
                        LastModifiedAt = x.LastModifiedAt,
                        LastModifiedUserId = x.LastModifiedUserId,
                        LeadTime = y ==  null ?  7 : y.LoadingDay,
                        MTH = x.MTH,
                        NATIVE_ALT_FAMILY = x.NATIVE_ALT_FAMILY,
                        NATIVE_INV_ITEM = x.NATIVE_INV_ITEM,
                        PLATTER = x.PLATTER,
                        QTR = x.QTR,
                        RPM = x.RPM,
                        rpt_label = x.rpt_label,
                        WEEK = x.WEEK,
                        WKNUM = x.WKNUM
                    }).ToList();
}

当然,也可以用groupjoin来做,不过用SelectMany可以少敲几个代码……

2、内连接

 

private  string qtr, rpt;
private List<CommitDetail> _cdList;
private List<CommitDetailExt> _cdextList;
private List<HddProgramCutoffLeadSetup> _hpclsList;
         private  void loadData( string qtr,  string rpt)
        {
             using (DBConn db =  new DBConn())
            {
                 /// /
                 // rpt = "R8.2.0";
                
// qtr = "12-Q4";
                
//   this._cdListP = db.CommitDetail.ToList();
                 this._cdList = db.CommitDetail.Where(p => p.Deleted ==  false && p.rpt_label ==  this.rpt && p.QTR ==  this.qtr).ToList();
                 //  this._cdList = db.CommitDetail.Where(p => p.Deleted == false && p.rpt_label == rpt && p.QTR == qtr).ToList();
                 this._hpclsList = db.HddProgramCutoffLeadSetup.Where(p => p.Deleted ==  false).ToList();
                 this._ludayList = db.LU_DAY.ToList();
                 this._luweekList = db.LU_WEEK.ToList();
            }
_cdextList =  this._cdList.Join( this._hpclsList,
                    x =>  new { k1 = x.CAPACITY, k2 = x.NATIVE_ALT_FAMILY },
                    y =>  new { k1 = y.Capacity, k2 = y.Program },
                    (x, y) =>  new CommitDetailExt
                    {
                        CAPACITY = x.CAPACITY,
                        Commit_QTY = x.Commit_QTY,
                        ConcurrencyMark = x.ConcurrencyMark,
                        CreatedAt = x.CreatedAt,
                        CreatedUserId = x.CreatedUserId,
                        CUSTOMER_CODE = x.CUSTOMER_CODE,
                        Deleted = x.Deleted,
                        DEST_FAC = x.DEST_FAC,
                        FACTORY = x.FACTORY,
                        FMONTH = x.FMONTH,
                        FORM_FACTOR = x.FORM_FACTOR,
                        HEAD_COUNT = x.HEAD_COUNT,
                        LastModifiedAt = x.LastModifiedAt,
                        LastModifiedUserId = x.LastModifiedUserId,
                        LeadTime = y.LoadingDay,
                        MTH = x.MTH,
                        NATIVE_ALT_FAMILY = x.NATIVE_ALT_FAMILY,
                        NATIVE_INV_ITEM = x.NATIVE_INV_ITEM,
                        PLATTER = x.PLATTER,
                        QTR = x.QTR,
                        RPM = x.RPM,
                        rpt_label = x.rpt_label,
                        WEEK = x.WEEK,
                        WKNUM = x.WKNUM
                    }).ToList();
}
3、groupby分组
囧……没怎么遇到复杂的。大部分都是诸如此类……
             var cdgropList =  this._cdextList.GroupBy(p =>
                 new
                {
                    PROGRAM = p.NATIVE_ALT_FAMILY,
                    CAPACITY = p.CAPACITY,
                     // FACTORY = p.FACTORY,                    
                    PART_NO = p.NATIVE_INV_ITEM
                });

 

转载于:https://www.cnblogs.com/h500ml/archive/2012/05/29/2524265.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值