dnx ef is not recognized although defined in project.json - entity-framework-core

While starting my asp.net 5.0 application + EF 7 RC1. I get the message to apply model change so I click the apply button but then I get an error with the message I should run "dnx ef database update" from the command line. So I did on the CMD within my project with my migration folder and the context class.
But I get this error:
Error: Unable to load application or execute command 'EntityFramework.Commands'. Available commands: web, ef.
In the project.json there I have put the:
"commands": {
"ef": "EntityFramework.Commands"
}
What am I missing?

You're missing a reference to EntityFramework.Commands in that project. Add a reference to it in project.json.

Related

How to tell entitiy framework that my db context class is avaiable in core project to run the migration in diffrent project?

Dear Developers,
I am new to EF.
I have this project srtucture.
+ HrSoultion
+ <Application> // namespace project
- api // this is the mvc core project
+ <Core> // namespace project
- Entity// this is the project where I defined the models and db context class
Now I am confused where to run the add Add-Migration HrSoultion.Core.HrSoultionContext
Thanks ?
Option 1: Use command line
dotnet ef migrations add Init
Option 2: Select appropriate project before you run Add-Migration command in Package Manager Console. E.g.

Add-Migration works in Package Manager Console but not in CLI

When I run Add-Migration from Package Manager Console everything is alright. But I get an error when run it in .NET Core command-line interface.
I also got error in dotnet ef database update
Am I missing something or making a mistake?
Is your DbContext file in the Infrastructure Class library? If not, you can use the following command :
dotnet ef migrations add RemoveSeedData --project THE PROEJECT PATH CONTAINING DBCONTEXT
Example :
dotnet ef migrations add RemoveSeedData --project ../MyProject.Data

How to use EF6 (DB-first) with ASP.NET core web application(.NET framework 4.6.1)?

I am building asp.net core web application using full .NET framework 4.6.1 template like this-
My project.json shows-
"frameworks": {
"net461": { }
},
I wanted to use EF6 (not EF core), hence install entity framework using NuGet package manager using this command-
Install-Package Entityframework
Project.json added this entry-
"EntityFramework": "6.1.3",
When I am trying to create a DBcontext and model using below Command:
Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLENAME
It throws below error:
Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized
as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
As I understand (since I have Powershell v3.0 and .NET core 1.0.1), rest of the EF tools and dependencies are missing in my project.json. So which are tools and dependencies I need to add in my project.json to use EF6 (not EF core)?
Some of the options I can see are like below. But not sure which one is right for EF6
"EntityFramework.MicrosoftSqlServer":
"EntityFramework.SqlServer":
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
I didn't get what you mean by using core in .net but if you are targeting you project to old .net you need to install compatible version.
For .net 4.8 following package version will work:
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.1.25

Running EF migrations from Package Manager Console gives an error

I am trying to create a migration on an ASP.NET 5 / EF 7 project. In project.json I have:
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final"
// Other dependencies
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://localhost:5000",
"ef": "EntityFramework.Commands"
}
I ran "dnx ef migrations add 'Start'" on Developer Command Prompt inside the project folder and the migration was created without a problem ...
When I run "ef migrations add 'Start'" on Package Manage Console I get:
"ef : The term 'ef' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
I have no idea why I get this error ... The project.json seems fine ...
Am I missing some step here?
The Entity Framework doesn't offer this in the Package Manager Console currently. More information can be found here: https://github.com/aspnet/EntityFramework/issues/978

EF7: The term 'add-migration' is not recognized as the name of a cmdlet

I have framework version set to: dnx46 in project.json.
Also have the following packages:
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final"
}
However when I got into running enable-migrations command I get the following:
The term 'enable-migrations' is not recognized as the name of a cmdlet
Does anyone know how I get EF migrations running in latest .NET?
This is what worked for me to solve this issue:
Run:
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
In project.json add this (if not there already) to the "tools" section:
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final",
Useful reference: https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html
As ErikEJ mentioned, there is no "enable-migrations". You will need to use "Add-Migrations" instead. See official docs for EF Core's Powershell commands here: http://docs.efproject.net/en/latest/cli/powershell.html
There appears to be a bug in NuGet and Package Manager Console in some versions of Visual Studio. If cmdlets are not recognized after adding the Commands package, try restarting VS.
Also, dnx commands will not be supported after RC1. New (forthcoming) dotnet tooling will be available for RC2. See https://github.com/aspnet/EntityFramework/issues/3925
The only way I managed to get EntityFrameworkCore.Tools (which includes Add-Migration) working with the latest EF Core & VS 2015 was to manually call the init script from the Package Manager Console like so:
PM> %UserProfile%\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview1-final\tools\init.ps1
To add a new migration in EF7 use this command :
dnx ef migrations add YourMigrationUniqueName
There is no "enable-migrations" command in EF Core (EF7).
Just use "add-Migration"
Currently EF migrations are not supported out of the box:
https://github.com/aspnet/EntityFramework/issues/4497
I Haved the same probleam, i was using the PowerShell for the comand, but he work in Package Manager Console.
Try to run in ->
Tools -> NuGet Package Manager -> Package Manager Console