Entity Framework 6 (5) connection to Oracle

一世执手 提交于 2019-11-28 21:43:16

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.

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

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!