SoFunction
Updated on 2025-04-07

Problems and solutions encountered when creating an entity model of an oracle database using ef6

The data layer project in the solution initially used the solid model created by oracle 11g + ef5. During the pagination, I encountered the problem of a skip parameter of 0 and reported an error, and no relevant information was found.

So I decided to upgrade to ef6. I learned from the official website of oracle that Oracle Data Provider for .NET in ODAC 12c Release 3 starts to support ef6 (/cd/E56485_01/win.121/e55744/release_changes.htm#CIHGIAEG

Installation steps:

1. Install odac and download address/technetwork/database/windows/downloads/

2.The .net version of the data layer project is changed to 4.5 or above, use nuget to install EntityFramework 6++, and all install the latest stable version.

After installation, the following configuration items will be added

<configSections>
 <!-- For more information on Entity Framework configuration, visit /fwlink/?LinkID=237468 -->
 <section name="entityFramework" type=", EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 <section name="" type=", , Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
 </configSections>
 <entityFramework>
 <defaultConnectionFactory type=", EntityFramework">
  <parameters>
  <parameter value="mssqllocaldb" />
  </parameters>
 </defaultConnectionFactory>
 <providers>
  <provider invariantName="" type=", " />
  <provider invariantName="" type=", , Version=6.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
 </providers>
 </entityFramework>
 <>
 <DbProviderFactories>
  <remove invariant="" />
  <add name=", Managed Driver" invariant="" description="Oracle Data Provider for .NET, Managed Driver" type=", , Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
 </DbProviderFactories>
 </>
 <runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
  <publisherPolicy apply="no" />
  <assemblyIdentity name="" publicKeyToken="89b483f429c47342" culture="neutral" />
  </dependentAssembly>
 </assemblyBinding>
 </runtime>
 <>
 <version number="*">
  <dataSources>
  <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
  </dataSources>
 </version>
 </>

Note the version number in entityFramework and . It is generally no problem to automatically generate nuget after installation. Before I installed, I put the configuration items in the information I found online, but the version number is inconsistent, the program cannot be started, and I have never noticed the version number.

I searched for a while and found out that these are these two places.

3. Then you can add the solid model. At this timeef6 compatible entity framework provider not found in vs, the ef section in the configuration file needs to be<provider invariantName="" type=", " />Delete or comment out, save and try to add the entity model again.

When adding a solid model, you need not select the table in the database first, that is, generate an empty model, then open the edmx file, select the solid model in the model browser, change the DDL generation template to (VS) in the properties, and change the database generation workflow to Generate Oracle Via T4 (TPT).xaml (VS).

The reason for this is that if the DDL generation template uses the default item, the entity attribute generated by the fields of type number(1,0) and number(2,0) in oracle will be int16, and then the mapping mismatch error will be reported when running (Error code 2019).

The reason for the error is that oracle uses a new default type mapping for ef6 since 12.1.0.2. The official website description/cd/E56485_01/win.121/e55744/#ODPNT8303, the New Default Mappings section.

The types of attributes generated by the template are number(1,0) corresponding to boolean, number(2,0) corresponding to byte. This correspondence is consistent with the new mapping.

Attached the mapping of ef5

Oracle Type Default EDM Type Custom EDM Type
Number(1,0) Int16 bool
Number(2,0) to Number(3,0) Int16 byte
Number(4,0) Int16 Int16
Number(5,0) Int16 Int32
Number(6,0) to Number(9,0) Int32 Int32
Number(10,0) Int32 Int64
Number(11,0) to Number(18,0) Int64 Int64
Number(19,0) Int64 Decimal

Summarize

The above is the problems and solutions encountered when using ef6 to create an oracle database entity model introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!