.net ef4分组依据和与导航条件求和
我有两张桌子.net ef4分组依据和与导航条件求和,.net,entity-framework,.net,Entity Framework,我有两张桌子 **table 1** int tid money money datetime date int serviceid int type **table2** int id int tid status nvarchr() 我用的是Ef4。我有两个实体的导航属性 我正在尝试按日期获取组的金额[我还使用此属性创建了一个新类] Total money Total money of type [1] total money where table2 status is a or b
**table 1**
int tid
money money
datetime date
int serviceid
int type
**table2**
int id
int tid
status nvarchr()
我用的是Ef4。我有两个实体的导航属性
我正在尝试按日期获取组的金额[我还使用此属性创建了一个新类]
Total money
Total money of type [1]
total money where table2 status is a or b
我怎样才能做到这一点呢
到目前为止,我得到的是:
return db.TBL1.Include("TBL2").Where(x => x.date >= startDate && x.date <= endDate && x.ServiceID == sid).GroupBy(e => new { e.Date.Value.Year, e.Date.Value.Month, e.Date.Value.Day }).AsEnumerable().Select(group => new entity c (Convert.ToInt32(group.Sum(x => x.Money)), Convert.ToInt32(group.Where(d => d.BillingType == 1).Sum(x => x.Money)),********what can i do here*****, Convert.ToDateTime(group.FirstOrDefault().Date))).AsEnumerable<billingReport>().ToList();
return db.TBL1.Include(“TBL2”).Where(x=>x.date>=startDate和x.date new{e.date.Value.Year,e.date.Value.Month,e.date.Value.Day}.AsEnumerable().Select(group=>new entity c(Convert.ToInt32(group.Sum(x=>x.Money)),Convert.ToInt32(group.Where(d=>d.BillingType==1).Sum(x=>x.Money)),*******我在这里可以做什么****,Convert.ToDateTime(group.FirstOrDefault().Date)).AsEnumerable().ToList();
返回db.TBL1
其中(x=>x.date>=startDate&&
x、 新日期
{
e、 Date.Value.Year,
e、 Date.Value.Month,
e、 日期、价值、日期
})
.选择(组=>new billingReport
{
TotalMoney=Convert.ToInt32(group.Sum(x=>x.Money)),
TotalMoneyOfType1=Convert.ToInt32(组,其中(d=>d.BillingType==1)
.Sum(x=>x.Money)),
TotalMoneyForStatus=group.Where(x=>x.TBL2.Any(y=>y.Status==“a”||
y、 状态==“b”))
.Sum(x=>x.Money),
日期=Convert.ToDateTime(group.FirstOrDefault().Date))
})
.ToList();
返回db.TBL1
其中(x=>x.date>=startDate&&
x、 新日期
{
e、 Date.Value.Year,
e、 Date.Value.Month,
e、 日期、价值、日期
})
.选择(组=>new billingReport
{
TotalMoney=Convert.ToInt32(group.Sum(x=>x.Money)),
TotalMoneyOfType1=Convert.ToInt32(组,其中(d=>d.BillingType==1)
.Sum(x=>x.Money)),
TotalMoneyForStatus=group.Where(x=>x.TBL2.Any(y=>y.Status==“a”||
y、 状态==“b”))
.Sum(x=>x.Money),
日期=Convert.ToDateTime(group.FirstOrDefault().Date))
})
.ToList();
return db.TBL1
.Where(x => x.date >= startDate &&
x.date <= endDate &&
x.ServiceID == sid)
.GroupBy(e => new
{
e.Date.Value.Year,
e.Date.Value.Month,
e.Date.Value.Day
})
.Select(group => new billingReport
{
TotalMoney = Convert.ToInt32(group.Sum(x => x.Money),
TotalMoneyOfType1 = Convert.ToInt32(group.Where(d => d.BillingType == 1)
.Sum(x => x.Money)),
TotalMoneyForStatus = group.Where(x=>x.TBL2.Any(y => y.Status == "a" ||
y.Status == "b"))
.Sum(x => x.Money),
Date = Convert.ToDateTime(group.FirstOrDefault().Date))
})
.ToList();