I am upgrading from EF 5 to EF 6. Previously I was using SQL Anywhere 12, and now I am using SQL Anywhere 17. I upgraded EF version, upgraded SQL anywhere version, but when I build, I get this error
Unable to cast object of type 'Sap.Data.SQLAnywhere.SAProviderServices' to type 'System.Data.Common.DbProviderServices'.
I have followed this tutorial
http://dcx.sap.com/index.html#sqla170/en/html/37fb9e8558e94547b66156b9298be16f.html
I installed SQL Anywhere provider which is required by EF 6. It is integrated to VS. I can make a connection using server explorer. But my edmx is not working fine. I removed my existing edmx and created a new one. But I still get this error. How to fix this error?
Please note that this is the XML given on the link http://dcx.sap.com/index.html#sqla170/en/html/37fb9e8558e94547b66156b9298be16f.html
<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>
In my case, to resolve the exception I found that I had to change it to this when you open the *.edmx file and choose "Update Model from Database...":
Next, pick to create a New Connection:
Then, choose your data source:
After you perform these, steps, Visual Studio will update your app.config for you:
<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>