Upgrading EF to 6 with SQL Anywhere 17. Edmx giving invalid cast exception

entity-framework-5 entity-framework-6 sqlanywhere

Question

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?

1
2
8/4/2015 9:46:06 AM

Popular Answer

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...":

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

Next, pick to create a New Connection:

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

Then, choose your data source:

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

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>
0
8/15/2017 10:10:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow