entity framework - Converting a datetime to date in iEF -


i have linq statement runs expected in linqpad (using linq sql) when bring c# app using ef 6, error saying cd.logtimestamp.date (in groupby statement) not supported. i'm attempting convert datetime2 value date value group purposes.

 helper.getdbcontext().sitelog      .where( sl => sl.siteid == 3 )      .groupby( cd => new { cd.siteid, cd.logtimestamp.date } )      .select( g => new dailytraffic()      {          siteid         = g.key.siteid,          trafficdate    = g.key.date,          newusers       = g.count( row => row.isnewuser ),          returningusers = g.count( row => row.isreturninguser ),          totalusers     = g.count( row => row.isnewuser ) + g.count( row => row.isreturninguser ),          pageviews      = g.count( row => row.ispageview )      } )      .orderby( g => g.siteid ).thenby( g => g.trafficdate )      .tolist(); 

is there preferred way convert datetime2 value date value in ef 6

using qa ( how use entity framework group date not date time ) guide, you'll want use entityfunctions can use built-in sql server functions directly, of course mean application won't portable other databases.

.groupby( cd => new { cd.siteid, entityfunctions.truncatetime( cd.logtimestamp ) } ) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -