Sto lavorando su Asp.net 5.0 mvc6 e sto volendo usare entityframework 6 perché 7 non è ancora completamente codificato e sono stato in grado di farlo fare tutto tranne la migrazione.Asp.net 5.0 MVC6 Script di migrazione EF6
Quando digito-abilitare la migrazione, add-migrazione o update-datatabase ottengo
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
Sono abbastanza sicuro che questi comandi non sono in PowerShell. Ho comunque trovato che ci sono strumenti in% userdir% .dnx \ packages \ EntityFramework \ 6.1.3 \ tools. Ricercando migrate.exe un po 'il poco che ho trovato mi hanno detto che funziona solo con i file proj e quindi non funziona con la nuova configurazione.
Ho anche provato ad andare via programmazione con questo codice nel costruttore di DbContext ho:
var configuration = new MigrationConfiguration();
var migrator = new DbMigrator(configuration);
migrator.Configuration.TargetDatabase = new DbConnectionInfo(nameOrConnectionString, "System.Data.SqlClient");
if (migrator.GetPendingMigrations())
{
migrator.Update();
}
e questo codice nel mio script di conferma:
public MigrationConfiguration()
{
AutomaticMigrationsEnabled = true;
MigrationsAssembly = Assembly.GetAssembly(typeof(InitialCreate));
MigrationsNamespace = "[Namespace of my migration scripts]";
}
Prima ho fatto qualsiasi di questo il database ha creato una tabella __migrationHistory con un 201509291902537_InitialCreate, quindi ho creato un file con quel nome e ne ho fatto un altro chiamato 201509291902538_test. Entrambi sembrano così:
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'");
}
}
}
Non importa quello che ho provato migrator.GetPendingMigrations() non dice che ha nuovi aggiornamenti e se ho fatto un aggiornamento falso e dire esattamente quello che ha bisogno di aggiornarlo ancora non funziona ma getta un'eccezione di riferimento null sulla funzione di aggiornamento.
Ecco la mia Migrator falso:
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": { }
}
}
ho provato sia con il nome della classe e il nome del file e nessuno dei due sembra funzionare.
Qualcuno ha avuto fortuna con una di queste cose o vedere cosa sto sbagliando con una di queste?
Non sono sicuro se le migrazioni siano ancora supportate in PowerShell: http://stackoverflow.com/questions/30220291/how-to-enable-migrations-ef6-in-an-asp-net-5-project –
Ho visto questo pure, ma l'unica cosa che dice è far funzionare migrate.exe che non so come farlo. –
puoi condividere il file project.json? –