In Visual Studio 2015, I created an ASP.net Core project (formerly called ASP.NET 5). The template for the project creates an MS SQL localdb for persistence, along with entity framework, and some authentication tables.
After I figured out how to browse the localdb database that was created for this project, I decided to try modifying a model object and attempting a Code First Migration with ASP.NET MVC Web Site template sample application. It uses EF to provide login persistence to a localdb. I tried using the
The demo app already includes a Migrations folder. But if you type add-migration SomeNameHere
into the Package manager console, or enable-migrations
it seems that it is not possible to work with the ER Migrations with the sample projects.
I added a string property to the IdentityModel.cs
unit, and I tried to manually add it by hand to the 0000...IdentitySchema.cs
file, but obviously I don't know how to do that correctly, as when I run the application, I got some errors, shown below. I believe I need to basically have the Entity Framework code-first tool generate some skeleton .cs unit that's going to go into the Migrations folder.
The usual things people suggest to do now are:
Reinstallation looked like this from package manager console:
PM> Uninstall-Package EntityFramework
Uninstalling NuGet package EntityFramework.7.0.0-beta4.
Successfully uninstalled 'EntityFramework.7.0.0-beta4' from WebApplicationDNX.
PM> Install-Package EntityFramework -IncludePrerelease
Installing NuGet package EntityFramework.7.0.0-beta4.
Successfully installed 'EntityFramework.7.0.0-beta4' to WebApplicationDNX.
PM>
Here I believe I'm making a mistake because I'm trying to run a command like add-migration and I'm unable to do it. It turns out this was never supported for me to try stuff like this:
PM> add-migration DummyMigrate
add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. ....
PM> enable-migration
enable-migration : The term 'enable-migration' is not recognized as the name of a cmdlet, function, script file, or operable program.
...
Is it possible to get an entity framework migration to work from Visual Studio 2015, from an ASP.NET 5 Preview Templates -> Web Site
template based application?
(updates 1 to 4 removed as they are for useless historical betas)
Update 5: In asp.net core 1.0.0-RC2 the dnx tool has gone away, replaced by dotnet, but the underlying principle that the dotnet ef
command must be run from your project source directory not from your solution directory, and to do so, you should probably use an external command prompt or use PowerShell Tools for Visual Studio, not the nuget command line prompt.
solution-dir project-source-dir
| |
d:\dev\AspNetCoreWebAp\src\AspNetCoreWebAp>dotnet ef
Project AspNetCoreWebAp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling AspNetCoreWebAp for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:03.0846647
_/\__
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\
Entity Framework .NET Core CLI Commands 1.0.0-preview1-20901
Usage: dotnet ef [options] [command]
Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.
The following is only applicable to dnx which was part of ASP.NET Core RC1. This has been replaced and is not applicable part of ASP.NET Core.
Answering your questions regarding the better way you're looking for to run the dnx command:
My dnx command was also giving the error.
The term 'dnx' is not recognized as the name of a cmdlet, function,
in both my Visual Studio package manager console and Windows powershell.
After much frustration I was able to resolve it.
Here are the steps I did to get it working
Navigate to the .dnx bin directory
cd\
cd users\YOURUSERNAME\.dnx\bin
Run the command
.\dnvm upgrade
If you an error message "execution of scripts is disabled on this system." then run the following command to give you permission first
Set-ExecutionPolicy RemoteSigned
Go Open Visual Studio. You will then be able to type the command dnx in both package manager console and powershell
dnx
and it will recognize it
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