c# - query to get all action during for each hour -
i want run , print query shows number of orders per each hr in day(24).
should like: hour-1:00, number of orders-5 hour-2:00, number of orders-45 hour-3:00, number of orders-25 hour-4:00, number of orders-3 hour-5:00, number of orders-43 , on...
i try:
public void showbesthours() { using (northwinddatacontext db = new northwinddatacontext()) { var query = z in db.orders select new stime { hourtime = db.orders.groupby(x => x.orderdate.value.hour).count(), }; foreach (var item in query) { console.writeline("hour : {0},order(s) number : {1}", item.hourtime, item.count); } } } public class stime { public int hourtime { get; set; } public int count { get; set; } }
you need alter query
var query = z in db.orders grouping z z.orderdate.value.hour g select new stime{ hourtime = g.key, count=g.count () };
or alternatively
var query = db,orders.groupby (o => o.orderdate.value.hour).select ( g => new stime{ hourtime=g.key, count=g.count () });
in re-create of northwind of orderdate values dates result hourtime = 0, count = 830.
i'm assuming you're experimenting grouping. seek grouping day of week this
var query = db.orders.groupby (o => o.orderdate.value.dayofweek).select ( g => new { dayofweek=g.key, count=g.count () });
which gives more useful result.
c# sql linq
No comments:
Post a Comment