Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 6 (5) connection to Oracle

I am attempting to write a Data Access library for our suite of applications that use Oracle in .net. We currently use NHibernate and are thinking of migrating away as it appears to not be supported all that well.

I am working with Visual Studio 2013 and we have already constructed our Oracle Database. We don't have writes to update it (that is the domain of the db guys). So that will not be part of any calculation on our end.

The client on the server is 32 bit, so we are going to stick with that for now. It is already GAC'd in there, and no need to change it. So we have the 32 bit client on our development boxes.

I have EntityFramework 6.1.0 installed into my project via nuget. I have ODAC 1.112.3.20 installed in my project. The 32bit version of the application. I also have the ODP.net.x86 driver installed (also via nuget).

The problem is that everytime I attempt to create an ADO.net Database connection, the oracle provider is never an option? What am I missing? What do I need to get this to work?

I read an oracle forum one time that said I need to set my Entity Framework to 5.0 and not 6.0. Which is fine, but how do I do that?

like image 664
SoftwareSavant Avatar asked Apr 25 '14 17:04

SoftwareSavant


2 Answers

EF 6 support is now provided by ODAC 12c Release 3 Beta:

From the .Net Developer newsletter (emphasis mine):

New Download: ODAC 12c Release 3 Beta The new ODAC beta includes Entity Framework 6, Code First, Code First Migrations, .NET Framework 4.5.2 certification, managed ODP.NET XML DB, and managed ODP.NET distributed transaction support without Oracle.ManagedDataAccessDTC.dll.

like image 175
Robert H Avatar answered Sep 28 '22 05:09

Robert H


I know this is getting a little old, but this is to answer the last part of your question (how to install EFv5). (Instructions written for VisualStudio 2013) with your solution open, click TOOLS->NuGet Package Manager->Package Manager Console. Enter the following:

Install-Package EntityFramework -Version 5.0.0

Edit

It’s been a while since I set up my machine, but I think this is what I had to do, hopefully it helps.

Setup:

  1. Install Oracle Instant Client (or whatever you do for an Oracle Home)
  2. Install ODTwithODAC121012 (if you Google that, it should come up)
  3. Make sure your tnsnames.ora is in the right place for your Oracle Home

Setting up a new Visual Studio Solution:

  1. New Solution (for me, of type ASP.NET Web Application)
  2. Run command as in original answer
  3. Add new project of type Class Library (for Model/Entities)
  4. In new project, add new Item of type ADO.NET Entity Data Model
  5. In Entity Data Model Wizard:
    1. EF Designer from database (if you are using an existing database)
    2. New Connection
    3. In Data Source, there is (hopefully) an Oracle Database option
    4. And below that, in data provider, I chose the ODP.NET Managed Driver
    5. Enter user/pass, select Data Source and name connection

Edit 2

Oh, I forgot one thing, not sure if it's important. You may need to add a reference in that Model project to the oracle driver. Right click project -> Add -> Reference -> Assemblies -> Search for 'oracle', hopefully there is an entry for Oracle.ManagedDataAccess (my version was 4.121.1.0)

A few rants:

  1. I don't think the process should be quite so difficult
  2. I don't know why it takes them so long to update either. http://www.devart.com/ seems to do just fine staying on top of new Oracle/Visual Studio changes (they charge, but so does Oracle)
  3. The conspiracy part of my brain says that Oracle has no interest in making it easier for you to not use their products and so they put no effort into it
  4. Their default number mappings can really screw you up. For example, if your Oracle DB has fields of type NUMBER(10), it will map it as a 32-bit int, when not all 10 digit numbers fit :(
  5. For more info on that mapping thing (the link shows how to override that 32-bit problem), see: http://docs.oracle.com/cd/E56485_01/win.121/e55744/InstallConfig.htm#ODPNT8167
like image 35
jordan.roskelley Avatar answered Sep 28 '22 04:09

jordan.roskelley