Web Api 2, Oracle and Entity Framework

I spent about two days trying to figure out how to expose the Oracle.ManagedDataAccess 4.121.1.0 library over a Web Api 2.2 OData v4 Endpoint. Looking through the Oracle documentation, Oracle Managed Data Access doesn’t currently support Entity Framework v6, so you have to use Entity Framework v5. DevArt supplies a Entity Framework 6 compatible product, unfortunately I didn’t have the time to get budget for this simple proof of concept and I haven’t had much luck with trial periods as they never seem to be active when I need them. When Oracle releases the ODP.NET 12c r3 libraries later summer 2014, this post will be deprecated as it comes with EF 6 support.

First thing is to install Entity Framework via NuGet Package Manager

Install-Package EntityFramework -Version 5.0.0

Next you need to install WebApi v2.2 with OData support.

Install-Package Microsoft.AspNet.OData

Finally you need to install the Oracle.ManagedDataAccess library, which is called ODP.NET.

Install-Package odp.net.managed

Now that all of the packages are installed, the oracle connection strings need to be setup. I had issues connecting to oracle 11g with the default “Data Source = xyz; user id= myuser; password = abcd123″ connection string. I received an error:

ORA-12154: TNS:could not resolve the connect identifier specified

Doing some research, you get this error when Oracle can not find the list of registered oracle servers on your network. I remember Sql Server having a discovery protocol similar to this, but I guess that the port numbers are not consistent the way they are in the Microsoft world so you have to go and specify the direct network location in the connection string.

Documentation stated that you should be able to install ODP.NET and point to the TnsNames.ora file to get the connection information. The TnsNames.ora file looks to be configured after the install, so I guess I got lucky there. Consulting with your Oracle DBA may help you locate the information for your server. This stackoverflow post gave me the connection string structure based on the ora file. You can’t just copy the values directly in there, you have to remove the Alias.

I wanted to configure the connection string in my web.config file instead of specifying it directly. To do that, you need the Oracle.ManagedDataAccess.Client.OracleClientFactory provider to be specified in the providerName field of the configuration file.


<connectionStrings>
<add name="myConnectionString" connectionString="from stackoverflow article" providerName = "Oracle.ManagedDataAccess.Client"/>

Adding this I received an error “Failed to find or load the registered .Net Framework Data Provider.”. This error occurs when the Oracle.ManagedDataAccess.Client.OracleClientFactory class isn’t registered in the web.config or machine.config. I don’t like putting assemblies in the GAC on production servers, so I’m glad this showed up on my workstation and not later in the release cycle. Adding the following to the configuration file resolved the error:


<system.data>
<DbProviderFactories>
<add name="Oracle ManagedDataAccess Provider"
invariant="Oracle.ManagedDataAccess.Client"
description=".Net Framework Data Provider for Oracle"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess" />
</DbProviderFactories>
</system.data>

With Entity Framework working, its time to focus on WebApi. Following any number of tutorials on the subject can get you stated, I used this one.

I made a few tweaks adding ODataRoutePrefixAttribute to my controller and ODataRoute to my action, but otherwise it is the same.

https://patrickhuber.wordpress.com/2014/07/09/web-api-2-oracle-and-entity-framework/

Web Api 2, Oracle and Entity Framework的更多相关文章

  1. Oracle 与 entity framework 6 的配置,文档

    官方文档: http://docs.oracle.com/cd/E56485_01/win.121/e55744/intro001.htm#ODPNT123 Oracle 对 微软 实体框架 EF6 ...

  2. [转]Porting to Oracle with Entity Framework NLog

    本文转自:http://izzydev.net/.net/oracle/entityframework/2017/02/01/Porting-to-Oracle-with-Entity-Framewo ...

  3. 《ASP.NET MVC4 WEB编程》学习笔记------Entity Framework的Database First、Model First和Code Only三种开发模式

    作者:张博出处:http://yilin.cnblogs.com Entity Framework支持Database First.Model First和Code Only三种开发模式,各模式的开发 ...

  4. 【ASP.NET Web API教程】2.3 与实体框架一起使用Web API

    原文:[ASP.NET Web API教程]2.3 与实体框架一起使用Web API 2.3 Using Web API with Entity Framework 2.3 与实体框架一起使用Web ...

  5. Entity Framework 6 vs NHibernate 4

    This article is dedicated to discussing the latest releases of the NHibernate and Entity Framework. ...

  6. Entity Framework 6.1-Code First【转】

      Entity Framework 6.1-Code First 分类: Entity Framework 2014-04-21 14:56 2034人阅读 评论(0) 收藏 举报 entityen ...

  7. Entity Framework Code First实现乐观并发

    Entity Framework Code First实现乐观并发 不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻喷,如觉得我翻译有问题请挪步原博客地址 本博文翻译自: h ...

  8. Entity Framework 6.0 Code First(转)

    源自:http://www.cnblogs.com/panchunting/tag/Code%20First/ 1 Conventions 2 Custom Conventions 3 Data An ...

  9. 【极力分享】[C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例【转载自https://segmentfault.com/a/1190000004152660】

      [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例 本文我们来学习一下在Entity Framework中使用Cont ...

随机推荐

  1. 算法——字符串匹配Rabin-Karp算法

    前言 Rabin-Karp字符串匹配算法和前面介绍的<朴素字符串匹配算法>类似,也是相应每一个字符进行比較.不同的是Rabin-Karp採用了把字符进行预处理,也就是对每一个字符进行相应进 ...

  2. ViewRootImpl和WindowManagerService笔记

    1.每个窗体的ViewRootImpl都有一个mWindowAttributes窗体属性,该属性在WindowManagerGlobal.updateViewLayout()->ViewRoot ...

  3. Directx11学习笔记【十四】 使用最新的Effect框架和SDK

    由于之前一直在看directx11龙书学习,因此sdk一直用的Microsoft DirectX SDK (June 2010) 版本,最近在stackoverflow上问dx11相关问题时,一直被大 ...

  4. MVC5 Entity Framework学习参加排序、筛选和排序功能

    上一篇文章实现Student 基本的实体CRUD操作.本文将展示如何Students Index页添加排序.筛选和分页功能. 以下是排序完成时.经过筛选和分页功能截图,您可以在列标题点击排序. 1.为 ...

  5. 【剑指offer】删除字符也出现在一个字符串

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27110873 剑指offer上的字符串相关题目. 题目:输入两个字符串,从第一字符串中删除 ...

  6. 【C++探索之旅】第一部分第二课:C++编程的必要软件

    内容简介 1.第一部分第二课:C++编程的必要软件 2.第一部分第三课预告:第一个C++程序 C++编程的必要软件 经过上一课之后,大家是不是摩拳擦掌,准备大干一场了呢. 这一课我们来做一些C++开发 ...

  7. 编程算法 - 分割数 代码(C)

    分割数 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n个无差别的物品, 将它们划分成不超过m组, 求出划分方法数模M的余数. 比如: n= ...

  8. Windows10微软在线账户与本地账户的切换方法

    Win10里面存在着两个账户,除了本地账户外,还有着一个微软在线账户,这个账户可以同步设置.日历等数据.不过对于大部分用户来说,本地账户已经足够我们使用了,那么这两个账户之间该如何切换呢? Win10 ...

  9. Mongodb安装和配置

    Mongodb之安装配置 安装 Mongodb的下载地址为Mongodb官网.下载时.你能够选择是安装包或者是压缩包. 下载完毕后.双击安装包并安装. 安装完毕后.你能够在安装文件夹看到下图中所见的文 ...

  10. VS2015在对GIT的支持

    VS2015在对GIT的支持 相比VS2013,VS2015在对GIT的支持上有了更强大的支持.本篇仅作抛砖引玉,不做过多介绍: 1. 打开VS 2015起始页 2. 打开团队资源管理器 打开[本地G ...