Steps and problems-use ef6 to create an oracle database entity model, ef6oracle

Source: Internet
Author: User

Steps and problems-use ef6 to create an oracle database entity model, ef6oracle

The data layer project in the solution initially uses the entity model created by oracle 11g + ef5. When the skip parameter is 0, an error is reported and no relevant information is found.

So I decided to upgrade to ef6, according to oracle official website, Oracle Data Provider for. NET in ODAC 12c Release 3 began to support ef6 (https://docs.oracle.com/cd/E56485_01/win.121/e55744/release_changes.htm#CIHGIAEG)

Installation steps:

1. Install odac, http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html

2.Change the. net version of the data layer project to 4.5 or later.Use nuget to install EntityFramework 6 + Oracle. ManagedDataAccess + Oracle. ManagedDataAccess. EntityFramework. The latest stable version is installed.

After installation, app. config and web. config will be added with the following configuration items:

<configSections>    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->    <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.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />  </configSections>  <entityFramework>    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">      <parameters>        <parameter value="mssqllocaldb" />      </parameters>    </defaultConnectionFactory>    <providers>      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.1.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.122.1.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" />      </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>    </version>  </oracle.manageddataaccess.client>

Note entityFramework and system. the version number in data, which is automatically generated after nuget is installed, is normal. I put the configuration items in the information found on the Internet before installation, but the version number is inconsistent and the program cannot be started, I have never noticed the version number,

After looking for a while, I found these two places.

3. Then you can add an object model. IfVs shows that the entity framework provider compatible with ef6 is not found., You must set <provider invariantName = "System. data. sqlClient "type =" System. data. entity. sqlServer. sqlProviderServices, EntityFramework. sqlServer "/> delete or comment out, save and try to add an object model again.

When adding an object model, you must first generate an empty model without selecting a table in the database. Then open the edmx file, select the entity model in the model browser, and change the DDL generation template to SSDLToOracle In the attribute. tt (VS), the database generation workflow is changed to Generate Oracle Via T4 (TPT ). xaml().

The reason for this is that if the DDL generation template uses the default itemSSDLToOracle. tt,The type of the object property generated by the number (2019) and number () fields in oracle is int16, And the ing Mismatch Error is reported during running (error code ).

The error message is that oracle uses the New Default type ing for ef6 starting from ODP. NET 12.1.0.2. The New Default Mappings section is described on the official website.

The attribute type generated by the SSDLToOracle. tt template is boolean and byte corresponding to number (1, 0) and number (2, 0), which is consistent with the new ing.

Attach the ef5 ing

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.