开发者

linq query with time zones groupby

I have a linq-to-sql query that works by grouping the data it retrieve in days for a particular month:

var Output = from c ....
             where .... // this is the month parameter
             group c by c.TheTime.Date into daygroups
             select new MyModel(){

       开发者_开发技巧         Prop1 = (from x in daygroups
                         where....
                         select x.ID).Count()
}.ToList();

The problem is that this groups by datetime in terms of server time. I'd like to group them by interval of times so that if we're looking at the result with California time, we're really looking at a list of days that starts at midnight PST.

The query returns a count. The solution I've figured out for now would be to return all the raw data between the beginning and the end of the month in a certain timezone, and then rearranging the raw data in days with the correct timezone, and only then do the count.

Is there a better way to do this?


Try grouping by c.TheTime.Date.AddHours(-8).
However, I'm not sure whether that will work correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜