我正在从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。但我仍然得到这个错误。如何解决此错误?
答案 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文件并选择“从数据库更新模型......”时我必须将其更改为:
接下来,选择创建一个新连接:
然后,选择您的数据源:
执行这些步骤后,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>