Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JetEntityFramework vs EF 6?

Tags:

Throwing this up here since the author asks for help requests to go to StackOverflow.

Have an existing app in progress, originally wrote to SQL Server. Sadly now there is a very old Access Database that I must talk to. Trying to use JetEntityFramework to help me out so I don't need to make wholesale substitutions. Out of the gate, this exception I throw. I suspect a problem with web.config as the documentation for setting this up correctly is sparse.

Error

System.InvalidOperationException was unhandled by user code
HResult=-2146233079 Message=The 'Instance' member of the Entity Framework provider type 'JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider, Version=1.2.4.0, Culture=neutral, PublicKeyToken=756cf6beb8fe7b41' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Here is the relevant snippet of my web.config (was asked to change the actual name of the DBContext and MDB file)

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="MyDBContext" 
         connectionString="Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MyAccessDB.MDB" 
         providerName="JetEntityFrameworkProvider.JetConnection" />
  </connectionStrings>
  <system.data>
    <DBProviderFactories>
      <remove invariant="JetEntityFrameworkProvider"/>
      <add invariant="JetEntityFrameworkProvider"
           name="Jet Entity Framework Provider"
           type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </DBProviderFactories>
  </system.data>
like image 647
JoeHz Avatar asked Jan 01 '17 19:01

JoeHz


1 Answers

In your example the provider uses JetEntityFrameworkProvider.JetProviderFactory as its type. This caused the above exception because it does not inherit from System.Data.Entity.Core.Common.DbProviderServices. From the video tutorial and also from inspecting the source code JetEntityFrameworkProvider.JetProviderServices is the type needed for the provider.

Based on the tutorial from the project site, check the following configuration that was shown as an example.

  <connectionStrings>
    <add name="MyDBContext" 
         connectionString="Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MyAccessDB.MDB" 
         providerName="JetEntityFrameworkProvider" />
  </connectionStrings>
 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider 
        invariantName="JetEntityFrameworkProvider" 
        type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider"/>
    </providers>
  </entityFramework>
  <system.data>
    <DBProviderFactories>
      <remove invariant="JetEntityFrameworkProvider"/>
      <add 
        invariant="JetEntityFrameworkProvider"
        name="Jet Entity Framework Provider"
        description="Jet Entity Framework Provider"
        type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider"/>
    </DBProviderFactories>
  </system.data>
like image 127
Nkosi Avatar answered Oct 11 '22 19:10

Nkosi