I'm attempting to use Entity Framework 6 within an addin for a program I don't have control over.
I've built a class library to contain my context / model logic and I want to be able to consume that within my addin assembly. I am able to consume it as desired within an application no problems, but consuming application requires an app.config file containing the available connection factories (in my case Sql and Sql Ce).
The addin must be compiled as a class library and as such the app.config file within that project is not used - instead I suspect it uses the app.config file of the program under which the addin runs. As a result I'm getting the exception 'No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information'
I've tried many weird and wonderful things with no success, I believe the closest I've come is the following:
Contained within the addin:
public static ProjectContext GetContext() {
SqlCeConnectionStringBuilder sqlBuilder = new SqlCeConnectionStringBuilder {
DataSource = @"C:\Test.sdf"
};
DbConnection connection = new SqlCeConnection(sqlBuilder.ToString());
return new ProjectContext(connection);
}
Contained within my API class libray:
public ProjectContext(DbConnection connection) : base(connection, true) {
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ProjectContext, Configuration>());
Database.CreateIfNotExists();
}
The exception occurs here, when trying to access data from the context (in the addin):
var ctx = GetContext();
List<Model> list = Project.Models.Where(model => model.ParentId == 0).ToList();
All of the above is 100% working when run in a separate application as a .exe with the EntityFramework NuGet packages for Sql and Sql Ce and an app.config file containing the following:
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
Is there anything I can do to make my program run as an addin in this case? I was hoping that passing the actual database connection to my ProjectContext would remove the dependency on the app.config providers list. Is there something that I've missed that can achieve this?
Most of what I've been able to find around this topic seems to be about passing in the connection string so I'm at a loss!
Thanks in advance!