Unable to add migration on Entity Framework - entity-framework-core

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 .

Related

Problem with Entity Framework 6 migrations

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

How to change Data Model directory to class library in .net Core2.0

For one of my project which has .net Core 2.0 framework with MVC I want to implement Onion layer architecture to my project. My main issue is that I want to implement EF and Data model to particular class library.But whenever I tries to scaffold it creates under my Web Application. I want to know why it creates by default under Models folder and is that possible to provide path for data model under different class library, if yes how and if no why ?
I have resolved the issue:-
Step 1:- Open Class library and right click on dependency add these 2 package using nuget
A. Microsoft.EntityFrameworkCore
B. Microsoft.EntityFrameworkCore.SqlServer
Step 2:- Open Package Manager Console, Select Default Project as your class library, and then execute below command
Scaffold-DbContext "Data Source=.\SQLEXPRESS;Initial Catalog=Your Instance Name;User ID=sa;Password=test#123" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

ADO.NET Entity Framework missing

I want to add Entity Framework to my project but for some reason the Item is missing. What do I do wrong? I´ve done this lika a 100 times before.
(I´ve tried by downloaded the nuget package, restarted my computer, created a new project and searched google.)
Try to go to Package Manager console and type:
install-package EntityFramework

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.

Issues adding second context to solution

I have multiple projects in my solution. What I am trying to do is get each plugin to have its own context.
When calling Enable-Migrations on the second project (making sure the drop down has my project selected), I get No context type was found in the assembly 'Plugin.Test'.. I do have a class in this project deriving from DbContext so am a little unsure as to what it wants.
This is the context in my second project:
public class SecondContext : DbContext, IDbContext
Could someone shed some light on how it's looking for a context so that I can make the changes to my second projects so it can be found?
p.s My first project EF integration is fine, this is purely when trying to add another context.
You can specify the context name:
Enable-Migrations -EnableAutomaticMigrations -ContextTypeName
NamespaceOfContext.ContextA -ProjectName ProjectContextIsInIfNotMainOne
-StartupProjectName NameOfMainProject -ConnectionStringName ContextA
For example:
Enable-Migrations -ContextTypeName SecondContext