实体框架4.3到Oracle:Web项目有效,NUnit没有

时间:2012-04-27 15:14:25

标签: entity-framework

我使用DevArt的提供程序针对Oracle数据库设置了Entity Framework 4.3。我通过NUnit 2.6测试运行器中的单元测试项目连接到数据库时遇到问题。有趣的是,我有一个ASP.NET MVC 3项目连接到它就好了。我在我的类库单元测试项目中创建了一个App.config,并将实体连接字符串信息复制到它。我错过了什么?

这是实体连接信息(在Web.config和App.config中相同):

  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/Entities.MagellanDataModel.csdl|res://*/Entities.MagellanDataModel.ssdl|res://*/Entities.MagellanDataModel.msl;provider=Devart.Data.Oracle;provider connection string=&quot;User Id=theusername;Password=thepassword;Server=theTNSname&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

以下是异常信息:

AppName.Tests.AccountRepositoryTests.GetByContactId:
System.Data.EntityException : The underlying provider failed on Open.
----> System.InvalidOperationException : Can not obtain Oracle client information
      from registry. Make sure that Oracle Client Software is installed, or use 
      Direct mode of connecting to server.

注意:Web和单元测试程序集都设置为编译为Any CPU。我在64位Windows 7上运行32位Oracle 10g数据库。我发现一个帖子似乎表明它与需要x86的平台相关,但我的web项目设置为Any CPU并且它运行正常。

2 个答案:

答案 0 :(得分:3)

我遇到了类似的问题:使用32位Oracle的Win7 64位DevArt。

适用于Web项目Any CPU,但控制台和单元测试项目失败。我通过在x86模式下为测试和控制台项目设置Debug来修复(或解决它)

答案 1 :(得分:0)

我有同样的问题。对我来说,这个问题可以通过取消选中&#39;首选32位&#39;来解决。项目属性中的复选框 - &gt;构建 - &gt;低于平台目标。我的平台目标设置为&#39;任何CPU&#39;。