Adding Entity Framework configuration in Visual Studio extension

100 views Asked by At

Here's my solution architecture:

  • VM (class lib) => references SQLite.
  • App (WPF Desktop App) => references VM.
  • VSIX (Visual Studio extension) => references VM.

I have copied EF providers related stuff from app.config of VM project to both desktop app and VSIX projects. The desktop app works fine whereas the VSIX project throws the following exception:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

Is there something special I need to do in case of extension projects?

1

There are 1 answers

0
dotNET On BEST ANSWER

Adding the last line in the following class fixed it for me:

public class SQLiteConfiguration : DbConfiguration
{
  public SQLiteConfiguration()
  {
    SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
    SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
    SetProviderServices("System.Data.SQLite", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
    SetProviderServices("System.Data.SQLite.EF6", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
  }
}

Not sure why this exception was only being thrown in VSIX project, and not the desktop app.

Might help someone down the road.