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
- my app has work both sql server , oracle. so...
- i started designing database in edmx diagram
- once diagram done, generated ddl sql server.
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
- i wanted app use code first approach (just preference. think it's easier maintain)
- so connected sql server database , generated of classes schema.
- i got of unit tests passing , decided test oracle database
- even after changing date timestamp, still having problems milliseconds going in.
- i generated code first model in test visual studio solution
timestamp(6)
type in oracle, except when looked @onmodelcreating
code, did not generatehasprecision(6)
nor there decorators on property in generated c# poco class. - i noticed if have
hasprecision(6)
code inonmodelcreating
, code firstcreatedatabase()
make oracletimestamp(6)
. if don't, oracle ef provider usedate
i think if model first approach can set precision values in edmx diagram, i've heard it's bad practice.
Comments
Post a Comment