07-21-2023, 09:12 PM
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:
* Make sure you ran as administator. (Done)
* Make sure you uninstall the Entity Framework and Reinstall it into the Solution you want it active in(Done)
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]
[![enter image description here][1]][1]
[1]:
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:
* Make sure you ran as administator. (Done)
* Make sure you uninstall the Entity Framework and Reinstall it into the Solution you want it active in(Done)
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]
[![enter image description here][1]][1]
[1]: