How do I configure Entity framework in class Library project?

Copy your SQL connection string from library project's config file and paste it into the main project's config file which is your startup project. Which will resolve your issue.

Also, copy DbProviderFactories from library project to the main project's config file.


Based on the link you gave, probably you miss this part.

Now you can either create your own .config file in this project and add the connectionstring entry of your model or simply copy the App.config file that you created in the MyEntityModel project, in your Console App project. We will adopt the simpler way. Right click the project > Add Existing Item > Go to the MyEntityModel project and add the App.config file.

Explanation:

When you create a library and the library is referenced from another project, EF will read the config that is relative to start up project. You can do one of the following.

  • Copy the config from library's config (copy the file and paste it to start up project)
  • Create a new config but copy the connection string information and other EF related section
  • Add existing config by add existing item and add it as link to library's config

I have been working on creating class library that implements all EF (Entity Framework) functionality and followed the process outlined in http://www.dotnetcurry.com/showarticle.aspx?ID=617 but still it was giving errors.

The problem was version mismatch between EF framework and .Net framework. I was using .Net framework 5.0 but EF version was 6.0. After updating latest version of .Net framework, everything started working good. Always ensure EF and Dll version + EF and test project versions are always same.

I also downloaded and installed EFTools6.1.3ForVS2013, if that helps anyone. Other thing to remember is you have to install Entity Framework from Nuget in all projects that references EF Dll and copy connectionstring from Dll config file in test project's config file.

Hope this helps someone !!! Thanks,