After upgrading our project from using Entity Framework 5 to Entity Framework 6 (though NuGets update function) i get the following error on my generated Entities class:
Error 1 The type or namespace name 'Objects' does not exist in the namespace 'System.Data'
(are you missing an assembly reference?)
I understand that this is because the namespace has changed and i can manually fix the error by changing my imports from: using System.Data.Objects;
and using System.Data.Objects.DataClasses;
To: using System.Data.Entity.Core.Objects;
However the file is generated so i need to reapply this fix after every Update model from Database
. Is there something extra to change to get EF to generate the model without this error.
In this situation you can upgrade to EF5 using the following steps: Select Tools -> Library Package Manager -> Package Manager Console. Run Install-Package EntityFramework -version 5.0.
EF5 is built into the core of . NET 4.5, whereas EF6 has been shifted out, and is open source. This means that you must add the new EF6 assemblies to all of the relevant projects in the solution, in particular the entry project. This means that you must remove assembly System.
NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core. The recommended way to use Entity Framework 6 in an ASP.NET Core application is to put the EF6 context and model classes in a class library project that targets .
I think your problem is, that your T4 templates, which generate the entitties and the context are still in EF version 5.
First you have to delete the current code generation items, which are in the code behind of the model, namely <Modelname>.Context.tt
and <Modelname>.tt
.Next add a new EF version 6 code generator with Right click in the model designer-> Add Code Generation Item ... -> EF 6.x DbContext Generator
.
This is my experience on how to successfully upgrade Entity Framework v5 to v6 for:
Acronyms:
Checklist:
using System.Data.EntityClient;
, which is an EF5 reference.using System.Data.Entity.Core.EntityClient;
which is the correct for EF6.Still stuck? This checklist is a Community Wiki, feel free to edit this checklist to help other hapless souls who are still banging their heads against the brick wall that can be EF6 configuration.
Please explore other options before considering EF. It's 100x slower than other options, it's vastly over complicated for what it delivers, the entity GUI is full of bugs and has weird usability issues, and we are going to have to rip out all of our EF6 code and replace it with something that takes less than 5 minutes to make a query that takes 5 seconds in Dapper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With