Implementation of WEBAPI2 based on Oracle EntityFramework (i)--preparation work

Source: Internet
Author: User
Tags connectionstrings

Currently in. NET scope, good and convenient ORM is really not many, and the integration with VS convenient is also the EntityFramework (hereinafter referred to as EF, do not know why, total EF This abbreviation is not professional). However, many companies are using Oracle, resulting in the use of EF when there will be a variety of unpleasant situations, including the setting of the environment, are very painful. Recently there is a project in this way, and very successful, so, here to share with you, but also hope that the problem of the place to point out, together to improve.

The environment is configured by the following several important points:

    1. Oracle's ODP installation (includes Oracle invoke controls and Oracle's VS tools)
    2. Establishment of the WEBAPI project
    3. Installation of Microsoft EntityFramework6
    4. Change the managed reference for Oracle to an unmanaged reference (the number of bits that can be removed from the target environment)
Odp. NET Installation

Since installing odp.net, we need to restart VS, so let's install odp.net and then create a new project.

Download Oracle's DBAC (x86) (Cannot download please leave a message), turn off all vs, and then install the downloaded compressed package inside the Setup.exe. Install the settings of the two directories, must not have special characters, you can use the same, @, () and so do not have.

Establishment of the WEBAPI project

Open the new project interface for VS, choose c#-web-asp.net MVC, then fill in the project name, select where the project is located, and click OK.

The new window pops up and the action is selected as shown:

Then click OK to open a project, and the other configuration will be the same as other projects.

Introduction of EntityFramework

Open the tool, select NuGet Package Tool Management, if the diagram opens NuGet Package Manager:

Select Online, find the Entity Framework, point to install, install to just our WEBAPI project.

Referencing Oracle's Odp.net

Right-click a project reference • Add a new reference • Find oracle.manageddataaccess in the extension and Oracle.ManagedDataAccess.EntityFramework "Note 1". And then determine. At this point, these two things are successfully referenced in the project.

Add the following Web. config content to Web. config, and note that if there is the same, the original is replaced.

<configsections>    < Sectionname= "Oracle.manageddataaccess.client"type= "OracleInternal.Common.ODPMSectionHandler, oracle.manageddataaccess, version=4.121.2.0, Culture=neutral, publickeytoken=89b483f429c47342 " />    <!--for more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -    < Sectionname= "EntityFramework"type= "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=6.0.0.0, culture= Neutral, publickeytoken=b77a5c561934e089 "requirepermission= "false" />  </configsections>  <connectionStrings>  </connectionStrings>  <EntityFramework>    <defaultconnectionfactorytype= "Oracle.ManagedDataAccess.EntityFramework.OracleConnectionFactory, Oracle.ManagedDataAccess.EntityFramework, version=6.121.2.0, culture=neutral, publickeytoken=89b483f429c47342 "  />    <providers>      <providerInvariantName= "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>      <Removeinvariant= "Oracle.ManagedDataAccess.Client" />      <Addname= "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>  <oracle.manageddataaccess.client>    <version Number="*">      <Settings>        <settingname= "Tns_admin"value= "C:\TNS_ADMIN" />        <settingname= "Traceoption"value= "1" />        <settingname= "PerformanceCounters"value= "0" />      </Settings>    </version>  </oracle.manageddataaccess.client>

It is important to note that [Tns_admin] the value behind this thing points to the directory where TNS files are placed, if you do not use the TNS file to manage the IP address of the database, but instead use the IP connection directly in the connection string, you can not write this setting entry.

At this point, the preparation is fully completed.

Note 1: If you cannot find oracle.manageddataaccess and Oracle.ManagedDataAccess.EntityFramework at the time of reference, you can find these two files in the ODP installation package below, extract them into the project, and then directly Two files can be referenced. 】

Implementation of the WEBAPI2 of Oracle-based EntityFramework (i)--preparation work

Related Article

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.