【发布时间】:2017-03-08 00:55:28
【问题描述】:
我不知道如何显示,在asp.net MVC的表格中,开头月份的订单总和。 我在 Order 表中的数据如下所示:
创建日期 |总价
2017-02-06 | 400
2017-02-06 | 300
2017-03-06 | 100
2017-03-06 | 50
我想得到 TotalPrice 的总和,如下所示:
创建日期 |总价
2017-02 | 700
2017-03 | 150
我的模型类订单:
public int orderId { get; set; }
public string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
[StringLength(100)]
public string firstName { get; set; }
[StringLength(150)]
public string lastName { get; set; }
[StringLength(150)]
public string address { get; set; }
[StringLength(20)]
public string phoneNumber { get; set; }
public string email { get; set; }
public string comment { get; set; }
public DateTime dateCreated { get; set; }
public OrderState orderState { get; set; }
public decimal totalPrice { get; set; }
public List<OrderIteam> OrderIteams { get; set; }
我尝试写这样的东西来在表格中显示当月订单的总和:
public ActionResult ListOrder()
{
var result =
from s in db.Orders
group s by new { date = new DateTime(s.dateCreated.Year, s.dateCreated.Month, 1) } into g
select new
{
dateCreated = g.Key.date,
sumTotalPrice = g.Sum(x => x.totalPrice)
};
return View(result);
}
我收到错误消息:
传入字典的模型项的类型为“System.Data.Entity.Infrastructure.DbQuery
1[<>f__AnonymousType52[System.DateTime,System.Decimal]]”,但该字典需要一个“系统”类型的模型项.Collections.Generic.IEnumerable`1[Sklep_Internetowy.Models.Order]'。
最后我想将给定月份的订单总和如下图所示: Chart
【问题讨论】:
标签: asp.net asp.net-mvc linq charts