Oracle EntityFramework Core database first - change default type mappings

.net-core entity-framework-core oracle

Question


I'm using EF Core 2.2 with Oracles EF Core dataprovider - connecting against an existing database.

Is there any possibility to change those mappings as some tables are poorly set up:

  • Table A Key is NUMBER(decimal)
  • Table B Refrences Table A with a NUMBER(12) (long)

I can't change the tables as it, so I need to adjust my code.


Here is a document where the default mappings are shown :
https://docs.oracle.com/en/database/oracle/oracle-data-access-components/19.3/odpnt/EFCoreREDataTypeMapping.html#GUID-4FF3A9A3-AE49-431B-A4FB-31F8C53FCCF5
And I'm using asp.net core 2.2 and the latest official oracle ef core package: https://www.nuget.org/packages/Oracle.EntityFrameworkCore/

1
0
4/2/2020 11:31:58 AM

Popular Answer

Okay I got it: You have to just remove the database type from the annotation:

     [Table("TableA", Schema = "Schema")]
      public class TableA
      {
        [Key]
        [Column("KeyColumn")]
        public long KeyColumn { get; set; }

Instead of:

     [Table("TableA", Schema = "Schema")]
      public class TableA
      {
        [Key]
        [Column("KeyColumn", TypeName = "NUMBER")]
        //TypeName = Number isn't compatible with long
        public long KeyColumn{ get; set; }
0
4/2/2020 1:14:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow