Problem with Entity Framework 6 migrations - entity-framework

I have a problem with creating migration for Entity Framework 6 in code first approach. I already created migration, but later when I tried to create new, this was the errror:
Your target project 'Blog' doesn't reference EntityFramework. This
package is required for the Entity Framework Core Tools to work.
Ensure your target project is correct, install the package, and try
again.
I checked NuGet, EF6 is installed, alongside with these packages

Related

Unable to add migration on Entity Framework

When trying to add a migration add-migration "Inicial" -Verbose , this error message appears:
No migrations configuration type was found in the assembly 'DevIO.UI.Site'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
I followed the message instruction and typed the command Enable-Migrations, but there was still an error
No context type was found in the assembly 'DevIO.UI.Site'
What can I do?
Assuming you already have a DbContext class in your solution, you need to know which project it is in. You should be adding migrations in that project. If you're using the Visual Studio package manager console for this, you will need to set the Default Project to the project which contains the DbContext (i.e. in the dropdown at the top of package manager console).
Entity Framework is different from Entity Framework Core. You are using Entity Framework (which we know because EF Core doesn't include an Enable-Migrations command), but your DbContext is coming from the Microsoft.EntityFrameworkCore namespace. If you replace using Microsoft.EntityFrameworkCore with using System.Data.Entity that should be the correct DbContext class for Entity Framework.
I figured that if you install a NuGet packages named Microsoft.EntityFrameworkCore.Tools it will solve this problem .

Can't add Entity Framework migrations when project is split

I am porting a project from MVC 5 to MVC 6. My project has two components the MVC application itself and a assembly that has all of the database code in it, including all db models, and the DbContext.
In the assembly I modified the project.json to have the ef commands dll and removed it from the MVC project.json. I have ported over all of my models, etc. and the application is compiling without errors. I want to execute
dnx ef migrations add
from a command shell in the subdirectory of the assembly in the project. When I do that I get
No DbContext was found. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
What is the correct way to accomplish this type of project organization?
Make sure your run this command from the project.json that has your EF Commands and your DBContext. You will not be able to run this from the artifacts folder since dnx custom commands like ef are registered on a per project.json basis.
If you are not already on the latest beta, it would be a good opportunity to try it again on beta8 to make sure everything works.
PS: Not just dnvm upgrade but the tooling as well.
If nothing works, checkout this other question. You will need a Startup.cs but it doesn't need to run anything in particular. It just need able to configure the dependencies.

C# : Building or getting latest keeps adding entity 5 to packages while project has been upgraded to 6

After having updated a project using Nuget to Entity 6.1.3., this project keeps adding a package for Entity 5.0.0. when Getting latest of that project or when building it.
I already looked with low-level search (fileseek) but can't find any reference anymore in that project to EF5.
Already uninstalled the Entity package and reinstalled, but same result.
What else can I do to compeltely remove any reference to EF5 ?
Problem is solved in the meantime : there was an unloaded! project in which the packages.config still referenced the 5.0.0 framework. I didn't know that an unloaded project was still held into account when building.

EF code migration in reference dll coming through nuget

We have a situation. Our company has Framework build on .net which is used by products developed using that Framework. Now this Framework is using EF code first. We want to implement EF Code Migration though generated migrations definitions because our entities are there in one of the Framework project. So I have implemented it. But the situation is this Framework we are distributing to other products as Nuget package (internal).
Now the situation is lets say ProductA is consuming the package which has xyz.dll which has migrations enabled in it. Now the developers of "ProductA" wants to upgrade the database created by Framework EF code first using that xyz.dll migrations, but this dll is only added as referenced dll. So running command in package manager console like Update-Database is not working because project is not in the current solution and its in reference dll
How do I solve this?
This is actually pretty easy to solve, the project which you add your nuget package to also needs to reference EF.
You can actually enforce this inside your nuget packages with a dependency eg:
<dependencies>
<dependency id="EntityFramework" version="4.2.0.0" />
</dependencies>
in your nuspec (obviously update the version with the one you are using)
See: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Dependencies
and
http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files
for some more details around how the dependancy syntax works

How to Upgrade from Entity Framework 4.0 to 4.3

I have a project that uses Entity Framework 4.0. From within that project, I installed 4.3. Some changes appeared in my app.config indicating that I was now using 4.3. However, my generated code still inherits from ObjectContext and creates ObjectSets even if I delete and re-add the edmx. How do I get the generator to use DbContext and DbSets?
You must download DbContext T4 template from Visual studio gallery - you can get it from extension manager in Visual studio.