2

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?

toppless
  • 411
  • 1
  • 6
  • 16
  • Are you using the entities directly in your client? If so, yes, you need the reference. If you map to business or view models in your abstraction layer, you can avoid needing this reference in your client layer. – Maess Dec 18 '13 at 14:15
  • 1
    http://stackoverflow.com/a/15358941/1017882 < that any use to you? Avoiding the reference to EF in the client project is without doubt possible, it's a sound design choice to do as you're trying to do. Good luck. –  Dec 18 '13 at 14:18
  • I'm not using the entities in my client project. – toppless Dec 18 '13 at 15:19

1 Answers1

4

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);
    }
    ....
}
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
CodingMate
  • 333
  • 4
  • 16