c# - Oracle Entity Framework provider doesn't store DateTime.Now with milliseconds -


i have exact same question guy here.

why can't save current datetime.now using entity framework

but using sql server, , using oracle. (my application must work both)

his problem precision wasn't set correctly @ db level.

i've noticed if manually edit milliseconds in oracle database, ef can pull out correct timestamp milliseconds. when create entity datetime property "datetime.now" gets truncated.

the datecolumn1 attribute of oracle type timestamp

i logged insert statement

insert "schemaname"."tablename"("datecolumn1") values (:p0) --:p0:'5/14/2015 4:07:27 pm' (type = date)

the crazy thing works in sql server.

aha! awesome colleague had idea , worked!

in our ef code tried putting

protected override void onmodelcreating(dbmodelbuilder modelbuilder) {     modelbuilder.entity<entityclass>().property(p => p.timestamp).hasprecision(6); } 

and datetime.now milliseconds got stored database

update - it's worth mentioning how got in predicament

building database model first in "test" application

  1. my app has work both sql server , oracle. so...
  2. i started designing database in edmx diagram
  3. once diagram done, generated ddl sql server.
  4. for reason oracle ef provider couldn't generate ddl proceeded manually make changes sql server ddl correct syntactically

    1st problem - oracle ddl using date instead of timestamp. make sure use timestamp!!! datetime in oracle doesn't store milliseconds.

using code first database actual solution

  1. i wanted app use code first approach (just preference. think it's easier maintain)
  2. so connected sql server database , generated of classes schema.
  3. i got of unit tests passing , decided test oracle database
  4. even after changing date timestamp, still having problems milliseconds going in.
  5. i generated code first model in test visual studio solution timestamp(6) type in oracle, except when looked @ onmodelcreating code, did not generate hasprecision(6) nor there decorators on property in generated c# poco class.
  6. i noticed if have hasprecision(6) code in onmodelcreating, code firstcreatedatabase() make oracle timestamp(6). if don't, oracle ef provider use date

i think if model first approach can set precision values in edmx diagram, i've heard it's bad practice.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -