I have search date time fromdate – todate. I need to add dropdownlist "Catruc" but i dont know how to do at Linq.
Database select query "Catruc"
View:
Controller: how can i add "Catruc" into "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
Answers
View:
According to your query results, this should work:
If you also want to include the value in your select, you need to add it to the groupby: