Entity Framework 6 (5) connection to Oracle
Asked Answered
M

5

9

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?

Marguerita answered 25/4, 2014 at 17:41 Comment(3)
I don't think ODP.NET currently supports EF6. You would probably have to look at the DevArt's Oracle provider.Oscilloscope
On oracles forums they say you have to set it EF6 to EF5? How do you that?Marguerita
For those wondering: this StackOverFlow Question answers how to get EF5.Bridgeman
S
9

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.

Seko answered 26/9, 2014 at 16:6 Comment(0)
Y
8

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
Yashmak answered 10/7, 2014 at 21:6 Comment(3)
I appreciate it Jordan. I am still looking for answers to this. I recall trying that, and I still wasnt able to add an oracle connection. Which was the problem I was having. Do you have any experience with that?Marguerita
One thing I recently realized is that I have a pretty old version of the Oracle client installed on my machine... 11203, 32 bit. That is probably affecting my ability to connect to a great degree.Marguerita
@Yashmak Link in "a few rants" #5 is brokenPrototrophic
J
4

EF 6 is not yet supported by ODP.NET. See the release notes (README) for more info. EF6 will be supported shortly.

Edit: EF6 is now supported.

Jugurtha answered 26/4, 2014 at 5:53 Comment(2)
You know, this is quite frustrating. I had such high hopes of creating a great DAO that our applications could use. I might try NHibernate, but doesn't look like there are great tutorials out there. Any word on Using Entity Framework 5.0 to connect to Oracle?Marguerita
I am coming to this super-late, but Dapper is an option to get up and running easily with an Oracle option. What you miss is the ORM designer part -- but you can easily query into classes you roll your own. Sort of takes the fun out of designing against db-first, but still works.Extrajudicial
J
1

Sorry, I missed part of your question.

If you are using Visual Studio 2013, you must download Oracle Developer Tools for Visual Studio version 12.1.0.1.2 or later. With any older version, it will not be able to integrate with VS 2013.

Here is the download location: http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html

EF 6.0 is not supported yet but you can use EF5 providers in VS 2013. So my other answer is not really relevant.

Jugurtha answered 1/5, 2014 at 16:47 Comment(4)
Can you install that using Nuget, or is that the oracle client? I just found out that I have Oracle_CLient_11203 32 bit... What version of entity framework interfaces with that?Marguerita
I also forgot to mention that I can connect to our databases with the oracle client installed on my machine. I just can't connect to it from visual studio. I might be able to set up a connection string and all that jazz and write my own ORM tool, but I was really hoping to use entity framework to get this done.Marguerita
You must install Oracle Developer Tools 12.1.0.1.2 or later. There is no other way to use Entity Designer with Visual Studio 2013. It comes with the Oracle 12.1 client and will work against databases with versions as early as 10.2. You will install it into a new "oracle home" (subdirectory) which will minimize interference with your current set up. The tools you need are not available via nuget, which is not designed to install add-ins.Jugurtha
After designing using ODT 12.1, if you are required to use ODP.NET 11.2 in deployment, you can try swapping that in after you have designed all your entities....Jugurtha
V
0

Entity Framework 6 Code First

ODAC 12c R3 is the first ODP.NET release to certify with Entity Framework (EF) 6 and EF Code First. EF Code First is a popular development model for .NET object-relational mapping. Developers define the application domain model using source code, rather than with a designer or an XML-based configuration file. An EF Code First model's classes are defined in code through Plain Old CLR Objects (POCOs).

...

These features are all available in both managed and unmanaged ODP.NET.

http://cshay.blogspot.com/2014/09/odac-12c-release-3-beta-now-available.html

Varve answered 5/10, 2014 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.