Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Oracle DB EDMX: Upgrade ASP.NET Project and Entity Framework to use Oracle.ManagedDataAccess.Client

0.00/5 (No votes)
14 Jun 2020CPOL2 min read 8.7K   157  
Upgrade a legacy ASP.NET project to use managed Oracle.ManagedDataAccess.Client instead of unmanaged Oracle.DataAccess.Client while using Entity Framework DB first or EDMX.
A legacy ASP.NET web project, connecting to an Oracle database using entity framework DB first or EDMX using unmanaged Oracle.DataAccess.Client. This article is going to demonstrate the steps to upgrade the current project to use managed Oracle.ManagedDataAccess.Client instead of unmanaged Oracle.DataAccess.Client.

Background

It was an ASP.NET .NET Framework 4 project using EntityFramework 5 generated EDMX from an Oracle database schema utilizing Oracle.DataAccess.Client. Our aim is to use managed Oracle.ManagedDataAccess.Client and resolve any dependencies of unmanaged DLLs.

Project Framework Change

.NET Framework Upgrade

Upgrade the current project's target framework from .NET Framework 4.0 to .NET Framework 4.5. Right-click on the project and select the properties option and change the Target Framework as shown in the image.

Image 1

Image 2

Reference DLL & NuGet Package Upgrade

After any target framework change, it is a good practice to upgrade references DLLs to new target framework. So we are going to upgrade/reinstall existing NuGet packages to new targetFramework="net45".

XML
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AjaxControlToolkit" version="7.0725" targetFramework="net40" />
  <package id="AjaxMin" version="4.97.4951.28483" targetFramework="net40" />
  <package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
</packages>

To ----------------------------------

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AjaxControlToolkit" version="7.1213" targetFramework="net45" />
  <package id="AjaxMin" version="4.97.4951.28483" targetFramework="net45" />
  <package id="HtmlAgilityPack" version="1.11.23" targetFramework="net45" />
  <package id="EntityFramework" version="6.4.4" targetFramework="net45" />
</packages>

Entity Framework Change

We have already reinstalled/upgraded Entity Framework 5 To Entity Framework 6.4.4. To use Oracle managed data access feature, we are going to install new NuGet packages called Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework to our project.

XML
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
</packages>

To------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.4.4" targetFramework="net45" />
  <package id="Oracle.ManagedDataAccess" version="12.2.1100" targetFramework="net45" />
  <package id="Oracle.ManagedDataAccess.EntityFramework" version="12.2.1100" 
   targetFramework="net45" />
</packages>

EDMX

Open EDMX XML file using Visual Studio or Notepad and change Provider from Oracle.DataAccess.Client to Oracle.ManagedDataAccess.Client. Try to open the EDMX file in the design view from the Visual Studio and build the current project. This process may automatically modify a few things at the existing DbContext class.

XML
<!-- SSDL content -->
<Schema Namespace="Model.Store" Alias="Self" Provider="Oracle.DataAccess.Client" 
 ProviderManifestToken="11.1" 
 xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" 
 xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">

To -------------------------

<!-- SSDL content -->
<Schema Namespace="Model.Store" Alias="Self" Provider="Oracle.ManagedDataAccess.Client" 
 ProviderManifestToken="11.1" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">

DbContext Class

Due to the change in Entity Framework version, we need to change used namespaces of the DbContext class. Here are the changes I have to do in the current project.

C#
using System;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data.EntityClient;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

To --------------------

using System;
using System.ComponentModel;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

This may vary depending on the installed entity framework's version.

Connection String

At the connection string section of the web.config, change Provider from Oracle.DataAccess.Client to Oracle.ManagedDataAccess.Client.

XML
<add name="Entities" connectionString="metadata=res://*/Model.Model.csdl|
res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=Oracle.DataAccess.Client;
provider connection string=&quot;DATA SOURCE=xx.xx.xx.xx:xxxx/xxxx;PASSWORD=noidea;
PERSIST SECURITY INFO=True;USER ID=ATS&quot;" providerName="System.Data.EntityClient" />

To ----------------

<add name="Entities" connectionString="metadata=res://*/Model.Model.csdl|
res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=Oracle.ManagedDataAccess.Client;
provider connection string=&quot;DATA SOURCE=xx.xx.xx.xx:xxxx/xxxx;PASSWORD=noidea;
PERSIST SECURITY INFO=True;USER ID=ATS&quot;" providerName="System.Data.EntityClient" />

Other Things

OLD Db Connection to Oracle Connection

In our current project, there were some usages of OLE DB related classes to retrieve data from another Oracle database. As we are planning to use managed data access, we are going to change any usages of OLE DB related classes to Oracle related classes.

OleDbConnection
OleDbCommand
OleDbDataReader

To --------------------

OracleConnection
OracleCommand
OracleDataReader

Automatic Changes

This upgrade process is going to add/modify a few things to web.config automatically, related to the project framework, Entity Framework and DLL references.

XML
<compilation debug="true" targetFramework="4.0">

To ---------------------

<compilation debug="true" targetFramework="4.5">

same in packages.config file

Use Same EDMX With Different Prod/Test/Stage Schemas

If we need to use the same EDMX file for different schema, check out the following article.

Good Practices

After any change, it is a good practice to rebuild the current project. try to delete existing bin and obj folders manually if needed.

Download File Details

  • Before_update.zip: Actual old files
  • After_update.zip: After all modifications
  • Changes.zip: Changes we have done manually

Try to compare files side by side from Before_update.zip and After_update.zip folder.

History

  • 14th June, 2020: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)