简体   繁体   中英

Manually adding a reference to Entity Framework

I am working on a project that revolves around EF. I have the core layers of my project separated into different projects.

Unfortunately I constantly get errors that are happening because I am missing a reference to EntityFramework.SqlServer.dll in my project.

Adding the .dll file to my build folder fixes this issue, but I want to solve it by a "using" statement in my code, however I cannot do that as I am missing a reference to Entity Framework in my project.

I was wondering how do I add one?

*PS If I serach for EntityFramework in the "Add reference" panel, I don't get EF as an option.

**I could always install it with NuGet, but wouldn't that be redundant, since I already have it installed?

I had the same issue on a N-tier solution where the DAL uses EF.

I solved it by adding a reference to the EntityFramework.SqlServer.dll in the web project.

Go to references --> Add Reference --> in the dialog, choose COM and press browse . Then go to your project which is using EF and go to the projects bin folder where the EF references are stored. Select the EntityFramework.SqlServer.dll and add it.

Then right click on the newly added reference --> Properties --> Select Copy Local to true 在此输入图像描述

You can also use Nuget by right-click on your project -> Manage Nuget Packages, then search for "EntityFramework". Install the Entity Framework with Nuget from Microsoft.

It will add both EntityFramework and EntityFramework.SqlServer packages.

I have run into similar situation. the way I resolved it is as follows: Go to references -> under assembly references, select browse and go the current projects packages folder and browse to the entityframework.dll and entityframework.sqlserver.dll of a specific version that I am targeting my application to. This resolved build issues.

I also ran into this problem. I was accessing EF via a separate Data Access assembly, and EF worked perfectly when I called it from a test console app from within the SAME project, but it gave errors when trying to access it from my main application via an instance of my DAL Object.

I added the 2 references to the main application but it still gave errors.

Then I realised what the actual issue was. I needed to bring across the EF configuration sections from the App.config in my DAL project, into the main application.

Once I'd done this, everything worked perfectly. Basically you need to copy across the contents of the connectionStrings and entityFramework sections.

Otherwise, EF doesn't know how to connect itself.

Of course if your creating the EF connection in code inside your DAL, then you may not have this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM