none
Abstracting EF layer RRS feed

  • Question

  • My goal is to have all EF dependency in one class library.  This library contains a repository with all LINQ code so the client only receives POCOs.  I've built my own constructor in the EF library so the client can pass in the server/database to connect to.  After some errors while calling the repo methods, I added the following to my app.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
        </startup>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    </configuration>

    Now I'm receiving the following error:

    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.
    What's the solution to this problem?  Do I need to add an assembly to the GAC or ....

    • Moved by CoolDadTx Tuesday, March 20, 2018 5:32 PM EF related
    Tuesday, March 20, 2018 4:01 PM

Answers

  • Hello Wild.Bill.Work,

    My guess is there is a missing project reference/nuget package and the assembly is not being included in the build.  To verify all is well go to the output folder and check if the EntityFramework.SqlServer.dll is there.  If so then my guess is probably wrong or there is a version issue.  If my guess is right then check you package/project references so that the library is included.


    Cheers, Jeff

    Tuesday, March 20, 2018 7:37 PM
  • Thanks for the replies.  The config was handled in the appropriate exe project.  The reference to the Entity Framework was only made in the library project, not the exe project.  I was able to fix the issue by copying the EntityFramework.SqlServer dll from the library's bin folder to the exe's bin folder.  Kind of a hack, I should probably register it in the GAC.  I'll also have to remember this come deployment.
    Thursday, March 22, 2018 3:00 PM

All replies

  • The information should be kept at the root project's app.config  like a Windows form project that creates an exe or any desktop solution that creates an exe type is considered the root project in your situation.

    If it's a Web application then the information needs to be kept in the root Web.config.

    Of course, the app.config in a project type that creates an exe type, the app.config is copied over to programname.exe.config upon the successful build of the project. The programname.exe.config must be at the same location as the programname.exe so that .NET can find the configuration information, which is in the Bin folder of the project. 

    EF issues can be discussed at the EF forum.

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

     
    Tuesday, March 20, 2018 5:14 PM
  • Hello Wild.Bill.Work,

    My guess is there is a missing project reference/nuget package and the assembly is not being included in the build.  To verify all is well go to the output folder and check if the EntityFramework.SqlServer.dll is there.  If so then my guess is probably wrong or there is a version issue.  If my guess is right then check you package/project references so that the library is included.


    Cheers, Jeff

    Tuesday, March 20, 2018 7:37 PM
  • Hi Wild.Bill.Work,

    Based on your description, I create a simple demo and reproduce your issue on my side, as chilberto said, you need to install entity framework in your application, which reference the entity framework library project.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 21, 2018 5:32 AM
    Moderator
  • Thanks for the replies.  The config was handled in the appropriate exe project.  The reference to the Entity Framework was only made in the library project, not the exe project.  I was able to fix the issue by copying the EntityFramework.SqlServer dll from the library's bin folder to the exe's bin folder.  Kind of a hack, I should probably register it in the GAC.  I'll also have to remember this come deployment.
    Thursday, March 22, 2018 3:00 PM
  • Thanks for the replies.  The config was handled in the appropriate exe project.  The reference to the Entity Framework was only made in the library project, not the exe project.  I was able to fix the issue by copying the EntityFramework.SqlServer dll from the library's bin folder to the exe's bin folder.  Kind of a hack, I should probably register it in the GAC.  I'll also have to remember this come deployment.

    Or you can just install EF in both projects. It's always the project that references a project that has EF that EF should be installed in both projects.
    Thursday, March 22, 2018 7:44 PM