c# - EF 5.0 Oracle Code First set Precision to number types -


with entity framework 5.0 , odp.net trying build code first dbcontext existing oracle database. know approach not supported officially odp, maybe there workaround only problem still need solve.

all tables have keys of type number(18,0). simple example:

  • table

    > describe t_user   kuser  not null number(18,0) 
  • domain object

    public class user {       public long id { get; set; }       /* ... */   } 
  • mapping configuration

    modelbuilder.entity<user>()     .totable("t_user"); modelbuilder.entity<user>()     .property<long>(x => x.id)     .isrequired()     .hascolumntype("number")     .hascolumnname("kuser"); 

i cannot specify precision attribute though, because decimalpropertyconfiguration class (.property()) exposes precision , scale properties.

the result translated queries contain cast number 19 digits precision (default mapping int64), like: select cast( "extent1"."kuser" number(19,0)) "c1", /* ... */

the same casts done in join , clauses heavy performance impacts on each query.

in edmx xml file - have deprecated since hope not have use ever in future - had line:

<property name="kuser" type="number" nullable="false" precision="18" /> 

is possible manually set precision of property after ef model creation?

or maybe there way extend ef configuration classes , add custom numberpropertyconfiguration exposes precision property. fact edm namespace internal has stopped me pursuing latter path.

notes

  • i can not represent properties c# decimal type because have rewrite pretty domain layer.
  • i can not add fake long property wrap hidden decimal one, because long field needs used in linq-to-sql queries joins , select

updates

  • added call .hascolumntype("number") in primitivepropertyconfiguration, result same.
  • is feasible alter property facets traversing metadataworkspace?

    (this iobjectcontextadapter).objectcontext.metadataworkspace 

    i try myself possible , update results.
    no, metadataworkspace read only.

no cannot that. if you're using code first model defined code. if code says property long, won't mapped number() column in database.

the direct workarounds can think of ones mention, want avoid.

you can still use mapper, automapper (more info here), allows map ef entities domain entities. depending on how code implemented work, but, if leak ef linq functionalities domain logic, wouldn't work. try using automapper iqueryable extensions i'm not sure if work use case.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -