Asp.net 5.0 MVC6 EF6 Migration Scripts

I am working on Asp.net 5.0 mvc6 and I want to use entityframework 6 because 7 is not fully encoded yet and I was able to get it to do everything except migration.

When I type enable-migration, add-migration or update-datatabase, I get

enable-migration : The term 'enable-migration' 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. At line:1 char:1 + enable-migration + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (enable-migration:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 

I am sure that these commands are not in powershell. However, I found that there are tools in% userdir% .dnx \ packages \ EntityFramework \ 6.1.3 \ tools. Studying migrate.exe a bit, I found that they told me that it only works with proj files and therefore does not work with the new setting.

I also tried to execute the programming route using this code in the dbcontext constructor that I have:

  var configuration = new MigrationConfiguration(); var migrator = new DbMigrator(configuration); migrator.Configuration.TargetDatabase = new DbConnectionInfo(nameOrConnectionString, "System.Data.SqlClient"); if (migrator.GetPendingMigrations()) { migrator.Update(); } 

and this code in my confirmation script:

  public MigrationConfiguration() { AutomaticMigrationsEnabled = true; MigrationsAssembly = Assembly.GetAssembly(typeof(InitialCreate)); MigrationsNamespace = "[Namespace of my migration scripts]"; } 

Before I did this, the database made a __migrationHistory table with 201509291902537_InitialCreate in it, so I made one file with this name and made another name 201509291902538_test, they both look like this:

201509291902537_InitialCreate:

 namespace Infrastructure.EF.Migrations { using System.Data.Entity.Migrations; public partial class InitialCreate : DbMigration { public override void Up() { } } } 

201509291902538_test:

 namespace Infrastructure.EF.Migrations { using System; using System.Data.Entity.Migrations; public partial class test: DbMigration { public override void Up() { Sql("insert into LegalEntity (Id, Name ) values(" + Guid.NewGuid() + ", 'Test'"); } } } 

No matter what I tried migrator.GetPendingMigrations () never says that it has any new updates, and if I did a fake update and tell him what it needs to be updated, it still doesn't work, it just throws an exception to the link to the update function.

Here is my fake migrant:

 namespace Infrastructure.EF.Contexts { public class Migrator : DbMigrator { public Migrator(DbMigrationsConfiguration configuration) : base(configuration) { } public override IEnumerable<string> GetDatabaseMigrations() { return new List<string>() { "InitialCreate" }; } public override IEnumerable<string> GetLocalMigrations() { return new List<string>() { "InitialCreate", "test" }; } public override IEnumerable<string> GetPendingMigrations() { return new List<string>() { "test" }; } } } 

project.json:

 { "version": "1.0.0-*", "dependencies": { "Autofac.Framework.DependencyInjection": "4.0.0-beta5-*", "AutoMapper": "4.0.4", "EntityFramework": "6.1.3", "log4net": "2.0.3", "Microsoft.AspNet.Http.Abstractions": "1.0.0-beta5", "Microsoft.CSharp": "4.0.0-*", "Microsoft.Framework.Configuration.Json": "1.0.0-beta5", "RestSharp": "105.2.3", "System.Linq": "4.0.0-*", "System.Runtime": "4.0.10-*", "System.Threading": "4.0.10-*" }, "frameworks": { "dnx451": { } }, "configurations": { "DV": { }, "QA": { }, "TR": { }, "PR": { } } } 

I tried it with both the class name and the file name, and none of them work.

Is anyone lucky with any of these things or see what I'm doing wrong with one of them?

+7
powershell asp.net-core asp.net-core-mvc entity-framework-6
source share
2 answers

If you want to use EF6 with ASP.NET MVC6, then expose the EF6 repositories as Web API 2 in .NET 4.5 and consume them in ASP.NET MVC6.

I know a lot of additional work, I followed this approach to studying and developing MVC6 applications due to the existing level of access to EF6 data and similar problems in EF6-EF7 transitions.

+1
source share

Have you tried this: http://www.bricelam.net/2014/09/14/migrations-on-k.html ? This is for EF 7, but I think you could just change the version to EF6.

0
source share

All Articles