我有搜索日期时间从日期到日期。我需要添加下拉列表“Catruc”,但我不知道如何在Linq。
enter image description here
数据库选择查询“Catruc”
enter image description here
enter image description here
查看:
enter image description here
管理员:我怎样才能把“Catruc”加到“where”里面呢???
public DongphuocDbContext db = new DongphuocDbContext();
// GET: Report
public ActionResult Index(DateTime? start, DateTime? end)
{
var query = db.View_XeQuaTramReport;
if (start == null || end == null)
{
return View();
}
DateTime strStart = start.Value.Date;
DateTime strEnd = end.Value.Date;
var result = db.View_XeQuaTramReport
.Where(r => r.NgayCa >= strStart && r.NgayCa <= strEnd)
.GroupBy(r => new { r.LoaiVe, r.LoaiXe, r.Phi })
.Select(g => new XeQuaTramDTO
{
LoaiVe = g.Key.LoaiVe,
LoaiXe = g.Key.LoaiXe,
Phi = g.Key.Phi,
TongPhi = g.Sum(r => r.Phi),
TongXe = g.Count()
})
.OrderBy(r => new { r.LoaiVe, r.LoaiXe, r.Phi, r.TongPhi, r.TongXe })
.ToList();
return View(result);
}
}
2条答案
按热度按时间zsohkypk1#
根据您的查询结果,这应该可以工作:
如果您还想在select中包含该值,则需要将其添加到groupby:
bnl4lu3b2#
查看: