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();
}
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();
}
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
});
new
{
PROGRAM = p.NATIVE_ALT_FAMILY,
CAPACITY = p.CAPACITY,
// FACTORY = p.FACTORY,
PART_NO = p.NATIVE_INV_ITEM
});