这里unoinColumn返回所有日期没有重复,但我想按月获取日期组
month totalamount
7/2014 10000
8/2014 10000
enter code here var unoinDateColumn = (from agent in db.collections
where agent.Date_Time.Value.Year == thisYear
select agent.Date_Time).Union(from u in db.bank_deposit
where u.Date_Time.Value.Year == thisYear
select u.Date_Time).ToList();
答案 0 :(得分:0)
如果我理解的话,你可以做那样的事情。
您当然可以在一个查询中完成所有操作,但我不确定这会更容易阅读;)
var collections = db.Collections.Where(x => x.Date_Time.Value.Year == thisYear)
.Select(m => new {
dt = m.Date_Time.Value,
amount = m.Amount
});
var deposits = db.Collections.Where(x => x.Date_Time.Value.Year == thisYear)
.Select(m => new {
dt = m.Date_Time.Value,
amount = m.Amount
});
var result = collections.Union(deposits)
.GroupBy(m => m.dt.Month)
.Select(g => new {
date = g.First().dt.ToString("MM/yyyy"),
totalAmount = g.Sum(x => x.amount)
});