c# - .NET LINQ to entities group by date (day) -


i have same problem posted here: linq entities group-by failure using .date

however, answer not 100% correct. works in cases except when different timezones used. when different timezones used, groups on timezones. why? managed bypass using many entity functions.

int localoffset= convert.toint32(     timezone.currenttimezone.getutcoffset(datetime.now).totalminutes);  var results = (     perfentry in db.entry     (....)     select new {          perfentry.operation, perfentry.duration,          localtime = entityfunctions.addminutes(perfentry.start,              localoffset - entityfunctions.gettotaloffsetminutes(                 perfentry.start))      } ).groupby(x => new {      time = entityfunctions.truncatetime(         entityfunctions.createdatetime(x.localtime.value.year,             x.localtime.value.month, x.localtime.value.day, 0, 0, 0)),     x.operation } ).orderbydescending(a => a.key). select(g => new {     time = g.key.time,     ... }); 

is there out there knows how proper way? code ugly , inefficient.

update (warning):
realised function entityfunctions.createdatetime suffers bug. not compatible leap years, such year. 29 feb 2012 throw exception.

you can use utc datetime , trunkate time after it.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -