2

我有 2 张桌子

**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();
4

1 回答 1

0
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();
于 2012-05-28T10:58:47.170 回答