问题
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.
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.
回答1:
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.
回答2:
I am using EF6 and Oracle.ManagedDataAccess.Client in my project. After upgrading to EF6, I started getting the same error at runtime. Adding the following block to Web.Config solved the error.
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmNumberMapping>
<add NETType="int16" MinPrecision="1" MaxPrecision="4" DBType="Number"/>
</edmNumberMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
来源:https://stackoverflow.com/questions/19233237/mapping-boolean-property-to-oracle-using-entity-framework