Reputation: 33
I want to select data from SQL database using EF, select the last hour and then group by minute.
var result = _dbContext.views
.Where(x => x.Id == id && x.Created > DateTime.UtcNow.AddHours(-1))
.OrderBy(x => x.Created)
.GroupBy(x=> x.Created.Where({Range is 1 minute}));
Upvotes: 3
Views: 52
Reputation: 34152
DateTime
instance has a Minute
property which is an int
so you can use the x.Created.Minute
for grouping:
var result = _dbContext.views
.Where(x => x.Id == id && x.Created > DateTime.UtcNow.AddHours(-1))
.OrderBy(x => x.Created)
.GroupBy(x=> x.Created.Minute}));
Upvotes: 3