Kobek
Kobek

Reputation: 1211

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?

Upvotes: 5

Views: 31493

Answers (5)

Aggie Jon of 87
Aggie Jon of 87

Reputation: 109

Just my answer to my similar issue. I was getting red wiggles under my name space references in my "Tests" for my controllers. The answer was to do as suggested above. The TEST controller was missing the reference of the original Controller. The fix is to go the Reference of the Tests project and right click, Add Reference. In the new window it is the "Projects" drop down to the Solution tab and then to hit the check box to select the original project. I know this answer is very simple for a more experienced user, but it took the efforts of a couple of us to figure it out,

Upvotes: 0

Alexandre
Alexandre

Reputation: 59

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.

Upvotes: 5

Dave Oakley
Dave Oakley

Reputation: 736

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.

Upvotes: 0

LMKN
LMKN

Reputation: 111

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.

Upvotes: 0

Marcus Höglund
Marcus Höglund

Reputation: 16846

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 trueenter image description here

Upvotes: 7

Related Questions