Just in time! ASP.NET vNext continued!

ASP.NET vNext
I continue to be impressed with the changes being made to ASP.NET vNext. I thought all was lost without having the Package Manager that comes installed with Visual Studio but this is handle using the kpm or K Package Manager and command section found in the project.json.

I was looking for a way to use the EntityFramework migration commands and was informed that I could configure the migration tools similar to the command used to start a local instance of the webserver.

I just added the “ef”: “EntityFramework.Commands” to the project.json commands section:

{
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
"Microsoft.Framework.Logging": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Microsoft.Framework.Cache.Memory": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Hosting": "1.0.0-*",
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Core": "6.0.0-*",
"Microsoft.AspNet.Mvc.ModelBinding": "6.0.0-*",
"Microsoft.AspNet.Routing": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Security": "1.0.0-*",
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
"Microsoft.AspNet.Security.Facebook": "1.0.0-*",
"Microsoft.AspNet.Security.Twitter": "1.0.0-*",
"Microsoft.AspNet.Security.Google": "1.0.0-*",
"Microsoft.AspNet.Security.MicrosoftAccount": "1.0.0-*",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
"Microsoft.AspNet.Security.DataProtection": "1.0.0-*",
"EntityFramework.Commands": "7.0.0-*",
"EntityFramework.Core": "7.0.0-*",
"EntityFramework.Relational": "7.0.0-*",
"EntityFramework.InMemory": "7.0.0-*",
"EntityFramework.SqlServer": "7.0.0-*"
},
"commands": {
"ef": "EntityFramework.Commands",
"web": "Microsoft.AspNet.Hosting –server Microsoft.AspNet.Server.WebListener –server.urls http://localhost:8080",
"kestrel": "Microsoft.AspNet.Hosting –server Kestrel –server.urls http://localhost:8181"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.Framework.Logging.NLog": "1.0.0-*"
}
}
}
}

Then I executed k ef from the Powershell/Command prompt, and poof look what you get.

ef_migration

 

This is only the first step. You really need to understand how the EF Tools work in order to execute the commands correctly. After all, the K Runtime is still in prerelease and not all commands provide help. But next I wanted to scaffold the database based on the DbContext class I created. So, I execute the following command k migration add DbContextClassName. The DbContextClassName is just that. The name of your class that extended the DbContext, IdentityDbContext etc.

k_mirgration_add

The command creates a Migration Folder and a few files:

  1. 201502131657130_GreenShelterDbContext.cs which contains ‘public partial class GreenShelterDbContext : Migration’
  2. GreenShelterDbContextModelSnapshot.cs which contains ‘public class GreenShelterDbContextModelSnapshot : ModelSnapshot’
  3. 201502131657130_GreenShelterDbContext.Designer.cs which contains ‘public partial class GreenShelterDbContext : IMigrationMetadata’

Building blocks for migrating your database up or down.