使用SQL Anywhere将EF升级到6. 17. Edmx提供无效的强制转换异常

时间:2015-08-04 06:55:59

标签: entity-framework-5 entity-framework-6 sqlanywhere

我正在从EF 5升级到EF 6.以前我使用的是SQL Anywhere 12,现在我正在使用SQL Anywhere 17.我升级了EF版本,升级了SQL的任何版本,但是当我构建时,我收到此错误< / p>

Unable to cast object of type 'Sap.Data.SQLAnywhere.SAProviderServices' to type 'System.Data.Common.DbProviderServices'.

我已经按照本教程

http://dcx.sap.com/index.html#sqla170/en/html/37fb9e8558e94547b66156b9298be16f.html

我安装了EF 6所需的SQL Anywhere提供程序。它已集成到VS.我可以使用服务器资源管理器建立连接。但我的edmx工作不正常。我删除了现有的edmx并创建了一个新的edmx。但我仍然得到这个错误。如何解决此错误?

1 个答案:

答案 0 :(得分:0)

请注意,这是链接http://dcx.sap.com/index.html#sqla170/en/html/37fb9e8558e94547b66156b9298be16f.html

上提供的XML
  <system.data>      
      <DbProviderFactories>
          <clear />
          <add name="SQL Anywhere 17 Data Provider" invariant="Sap.Data.SQLAnywhere" description=".Net Framework Data Provider for SQL Anywhere 17" type="Sap.Data.SQLAnywhere.SAFactory, Sap.Data.SQLAnywhere.EF6, Version=17.0.0.10094, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />
      </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="Sap.Data.SQLAnywhere.SAConnectionFactory, Sap.Data.SQLAnywhere.EF6, Version=17.0.0.10094, Culture=neutral, PublicKeyToken=f222fc4333e0d400">
    </defaultConnectionFactory>
    <providers>
        <provider invariantName="Sap.Data.SQLAnywhere" type="Sap.Data.SQLAnywhere.SAProviderServices, Sap.Data.SQLAnywhere.EF6, Version=17.0.0.10094, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />
    </providers>
  </entityFramework>

在我的情况下,为了解决异常,我发现当你打开* .edmx文件并选择“从数据库更新模型......”时我必须将其更改为:

https://ibb.co/kOhapv enter image description here

接下来,选择创建一个新连接:

https://ibb.co/cq7Qpv enter image description here

然后,选择您的数据源:

http://ibb.co/iXaOba enter image description here

执行这些步骤后,Visual Studio将为您更新app.config:

  <system.data>  
    <DbProviderFactories>
      <remove invariant="Sap.Data.SQLAnywhere" />
      <add name="SQL Anywhere 17 Data Provider" invariant="Sap.Data.SQLAnywhere" description=".Net Framework Data Provider for SQL Anywhere 17" type="Sap.Data.SQLAnywhere.SAFactory, Sap.Data.SQLAnywhere.EF6, Version=17.0.7.33824, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="Sap.Data.SQLAnywhere.SAConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="Sap.Data.SQLAnywhere" type="Sap.Data.SQLAnywhere.SAProviderServices, Sap.Data.SQLAnywhere.EF6, Version=17.0.7.33824, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />
    </providers>
  </entityFramework>