c# - Rounding a specific Hour in LINQ to Entities -


i wonder how following sql code can converted linq.

declare @t table( hour datetime )  insert @t select '19000101 14:38:12' union select '19000101 09:21:55'  select   hour,   case      when datepart( minute, hour ) >= 30      left(convert(varchar, dateadd( hour, 1, hour ) , 108),2)+':00:00'      else left(convert(varchar, hour , 108),2)+':00:00'    end  @t  

my current query is:

list<registrovehiculo> listaregistrovehiculocompleta =    (from r in db.registrovehiculo    r.idpersona == opersona.id       && r.tiporegistro == "s"       && (            (ohoraextrageneral.fechadesde <= r.fecharegistro && r.fecharegistro <= ohoraextrageneral.fechahasta)             ||            (ohoraextrageneral.fechadesde <= r.fechaentrada && r.fechaentrada <= ohoraextrageneral.fechahasta)          )     orderby r.fecharegistro     select r).tolist<registrovehiculo>(); 

how can make list rounded hours work?

have tried using let clause inside linq query?

look, this:

var xx = (from r in li           let roundhour = r.fecharegistro.minute >= 30 ?                           timespan.fromhours(r.fecharegistro.hour + 1) :                           timespan.fromhours(r.fecharegistro.hour)           r.tiporegistro == "s" //whatever else goes here sake of brevity           orderby r.fecharegistro           select new { rounded = roundhour,                         registro = r}).tolist(); 

please note instead retrieving list of registrovehiculo, return anonymous type, so, every occurrence, you'll receive 2 things:

  • the rounded hour
  • the registrovehiculo object

i hope approach helps you!

regards


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -