gpt4 book ai didi

c# - 如何在 EF 6 提供程序配置文件中添加/激活 "Oracle.ManagedDataAccess.Client"?

转载 作者:行者123 更新时间:2023-11-30 18:21:29 24 4
gpt4 key购买 nike

我正在学习使用 VS2013 创建 ASP.Net MVC Web 应用程序 these video series .当我收到以下错误时:

No Entity Framework provider found for the ADO.NET provider with invariant name 'Oracle.ManagedDataAccess.Client'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

(在视频中,使用的数据库提供程序是自然的 System.Data.SqlClient for ASP.Net application,但我需要使用 Oracle.ManagedDataAccess.Client )

错误本身是not new所以。而且,正如错误消息和 SO 问题的已接受答案所建议的那样,我检查了 EF 6.0 是否支持 ODP.Net 提供程序,我发现 it is .尽管如此,我仍然无法让它工作。

我是 MVC 的新手,所以如果有任何我目前理解错误的 MVC 应用程序/设置概念,我会寻求您的理解,我愿意接受您的更正。

一些可能有用的附加信息:

  • 我使用 VS2013 提供的 ASP.Net Web 应用程序模板开始该项目。我为它使用 MVC 模板,只有“添加文件夹和核心“MVC”的引用资料。我既不“添加单元测试”也不“在云中托管”
  • 模板中没有app.config文件,但是有Web.config文件(这有什么区别吗?报错提示消息“确保提供者已在“entityFramework”部分注册应用程序配置文件”。)
  • 在 Web.config 文件中,我发现了以下 entityFramework 部分:
    <entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
  • 我注意到有

    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />` 

    在那里排队。因此我尝试类似地添加:

    <provider invariantName="Oracle.ManagedDataAccess.Client" type=???, EntityFramework.???" />

    但是不知道type属性和EntityFramework.???要写什么,卡了几个小时。如果我不放它,我会收到以下警告:

    The required attribute "type" is missing

    如有任何帮助,我们将不胜感激。

如果您知道除了添加提供程序来解决此问题之外我还需要做任何其他事情,我也愿意。我在 web.config 文件中的连接字符串如下:

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcWebApplication1-20160212010850.mdf;Initial Catalog=aspnet-MvcWebApplication1-20160212010850;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="EmployeeContext" connectionString="Data source=aaaaa;user id=bbbbbb;password=cccccc;persist security info=True" providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>

最佳答案

我从an Oracle's ODP.Net document得到了答案和 an Oracle Community forum :

显然,根据公认的答案,直到 2014 年初,EF 6 才不受 ODAC 的支持,如其 document 中所述.必须部分使用 EF 5 才能使用 Oracle.ManagedDataAccess

但是,当我检查接受的答案所指的文档时,我没有找到暗示回答者所写内容的声明 - 这让我相信截至目前,Oracle.ManagedDataAccess 可以已在 EF 6 中得到支持。

然后我找到了this document其中包含相当多的技巧来解决在 EF 6 中使用 Oracle.ManagedDataAccess 时可能出现的问题。

特别适合我的方法是添加:

  1. 配置部分
    <configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
  1. 依赖程序集

    <dependentAssembly>
    <publisherPolicy apply="no" />
    <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
    <bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0" />
    </dependentAssembly>

    (我使用的是 Oracle.ManagedDataAccess 版本 4.121.2.0)

  2. Entity Framework 提供者

    <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

全部在Web.config文件中

关于c# - 如何在 EF 6 提供程序配置文件中添加/激活 "Oracle.ManagedDataAccess.Client"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35401627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com