toppless
toppless

Reputation: 411

.NET Entity Framework - Package structure

i'm trying to set up a simple three layer solution with following projects: - Client (WPF) - Service (Model abstraction layer) - Model (using Entity Framework installed with NuGet)

My expectation was to reference Model and Service layers only to the Entity Framework libraries, but in this case application won't start with the error message:

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

As described on the "more information" homepage, I have to add the entity provider configuration to the start-up project of my solution (Client). In this case "Client" must be aware of the persistence technology used in model.

Is there a possibility to avoid the reference to the Entity Framework in the "Client" project?

Upvotes: 2

Views: 1228

Answers (1)

CodingMate
CodingMate

Reputation: 343

I don't know if you already found a solution for this problem or not. But I encountered this problem and found the solution and surprisingly it works.

In the "xxx.Context.cs" file, add the following code in the main constructor:

public partial class MyOwnContext : DbContext
{
    public MyOwnContext()
    {
        var _ = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
    }
    ....
}

Upvotes: 4

Related Questions