Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping Boolean property to Oracle using Entity Framework

I need to connect a system to oracle using entity model first. I have a model with the entity "Entity1". "MyBool", as the name says, it's a boolean property.

enter image description here

I sucessfully generated the sql script from the model and run it on oracle database.

Then I have this code:

static void Main(string[] args)
{
    Model1Container context = new Model1Container();
    Entity1 entity = context.Entity1.FirstOrDefault();
}

This code throws this exception:

Schema specified is not valid. Errors: Model1.msl(8,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=False,DefaultValue=]' of member 'MyBool' in type 'Model1.Entity1' is not compatible with 'OracleEFProvider.number[Nullable=False,DefaultValue=,Precision=1,Scale=0]' of member 'MyBool' in type 'Model1.Store.Entity1'.

I've read a lot of threads and many people said to add:

  <oracle.dataaccess.client>
    <settings>
      <add name="bool" value="edmmapping number(1,0)" />
    </settings>
  </oracle.dataaccess.client>

In config file (in my case it's a console app then app.config). But this didn't changed anything. Indeed I can set any value on this parameter and the error will be exactly the same. It looks like this parameter is not being read.

Then some people said: Add Oracle.DataAccess DLL to the project. Which I did, and the results were the same.

I know that are a lot of threads about this topic, but any of them helped me, and I don't know what else to do. Just to notice, my real application model is already on production on Sql Server.

like image 536
Thiago Avatar asked Oct 03 '22 18:10

Thiago


1 Answers

After doing some research I found that it's perfectly alright to have custom mapping for database number(1) mapping to .net bool type. The downside is of course the 2019 mapping error (or schema validation error). If you want to get rid of the mapping error which usually don't cause any problem to the solution build is to turn off model validation during build, set the "Validate On Build" to false.

like image 53
Mrinal Das Avatar answered Oct 13 '22 10:10

Mrinal Das