Hello,
I am having some problems with mapping between Entity Framework and Oracle.
I have an existing Oracle database.
I create a new solution and a new project (.net 4.5) to which I add the following NuGet packages (EF and the official ODP.Net packages):
- package id="EntityFramework" version="6.1.3"
- package id="Oracle.ManagedDataAccess" version="12.1.24160419"
- package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.2400"
Here is my App.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no" />
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
</dataSources>
<edmMappings>
<edmMapping dataType="number">
<add name="int64" precision="10" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
<!-- connection strings excluded -->
</configuration>
I then add a new ADO.NET Entity Data Model using EF Designer from databse (model first).
I have a table PROCESS with a LINK_ID column that is defined as NUMBER (10) in Oracle.
The generated .edmx files and entites (generated through the tt file) use a normal int (Int32) rather than a long (Int64) as specified in my mapping.
I would like for the generated model to use a long.
I can go and change this manually, but then I get the following error at run time:
Schema specified is not valid. Errors: \r\nTestMappings2.msl(18,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Int64[Nullable=True,DefaultValue=]' of member 'LINK_ID' in type 'Model.PROCESS' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=10,Scale=0]' of member 'LINK_ID' in type 'Model.Store.PROCESS'.
How can I make the generated model use the correct type and why does changing the type give me a runtime mapping error?
Thanks.