每天查询物品
Query for items per day
这是我的店铺:
<ext:Store ID="itemsPerDayStore" OnReadData="itemsPerDayStore_ReadData" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Day" />
<ext:ModelField Name="Items" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
项目table是这个:
Items ( Itemid | DayPurchased )
我如何编写查询来 return 每天的项目数?商店将用于填充每日物品数图表。
using System;
using System.Collections.Generic;
using System.Linq;
public class Item
{
public int Itemid { get; set; }
public DateTime DayPurchased { get; set; }
}
public partial class Default : System.Web.UI.Page
{
protected void itemsPerDayStore_ReadData(object sender, Ext.Net.StoreReadDataEventArgs e)
{
// Sample data. Replace items from database
IEnumerable<Item> Items = new Item[]
{
new Item { Itemid = 1, DayPurchased = DateTime.Today },
new Item { Itemid = 2, DayPurchased = DateTime.Today },
new Item { Itemid = 3, DayPurchased = DateTime.Today },
new Item { Itemid = 4, DayPurchased = DateTime.Today.AddDays(-1) },
new Item { Itemid = 5, DayPurchased = DateTime.Today.AddDays(-1) },
new Item { Itemid = 6, DayPurchased = DateTime.Today.AddDays(-2) }
};
itemsPerDayStore.DataSource = Items.GroupBy(x => x.DayPurchased.Day).Select(x => new
{
Day = x.Key,
Items = x.Count()
});
itemsPerDayStore.DataBind();
}
}
记得第一次重新加载您的商店。像这样:
<ext:ResourceManager runat="server">
<Listeners>
<DocumentReady Handler="#{itemsPerDayStore}.reload();" />
</Listeners>
</ext:ResourceManager>
这是我的店铺:
<ext:Store ID="itemsPerDayStore" OnReadData="itemsPerDayStore_ReadData" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Day" />
<ext:ModelField Name="Items" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
项目table是这个:
Items ( Itemid | DayPurchased )
我如何编写查询来 return 每天的项目数?商店将用于填充每日物品数图表。
using System;
using System.Collections.Generic;
using System.Linq;
public class Item
{
public int Itemid { get; set; }
public DateTime DayPurchased { get; set; }
}
public partial class Default : System.Web.UI.Page
{
protected void itemsPerDayStore_ReadData(object sender, Ext.Net.StoreReadDataEventArgs e)
{
// Sample data. Replace items from database
IEnumerable<Item> Items = new Item[]
{
new Item { Itemid = 1, DayPurchased = DateTime.Today },
new Item { Itemid = 2, DayPurchased = DateTime.Today },
new Item { Itemid = 3, DayPurchased = DateTime.Today },
new Item { Itemid = 4, DayPurchased = DateTime.Today.AddDays(-1) },
new Item { Itemid = 5, DayPurchased = DateTime.Today.AddDays(-1) },
new Item { Itemid = 6, DayPurchased = DateTime.Today.AddDays(-2) }
};
itemsPerDayStore.DataSource = Items.GroupBy(x => x.DayPurchased.Day).Select(x => new
{
Day = x.Key,
Items = x.Count()
});
itemsPerDayStore.DataBind();
}
}
记得第一次重新加载您的商店。像这样:
<ext:ResourceManager runat="server">
<Listeners>
<DocumentReady Handler="#{itemsPerDayStore}.reload();" />
</Listeners>
</ext:ResourceManager>