2016-02-12 48 views
5

Próbuję zmienić tabelę w Entity Framework 6 ze złączami mysql.AlterProcedureException, gdy próbuję polecenia aktualizacji bazy danych EF6 MYSQL

Błąd jest:

PM> update-database -verbose 
Using StartUp project 'Facade'. 
Using NuGet project 'DAL'. 
Specify the '-Verbose' flag to view the SQL statements being applied to the target database. 
Target database is: 'GiveAndGet' (DataSource: localhost, Provider: MySql.Data.MySqlClient, Origin: Configuration). 
Applying explicit migrations: [201602122108206_2]. 
Applying explicit migration: 201602122108206_2. 
System.NotImplementedException: AlterProcedureOperation 
    en MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken) 
    en System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId) 
    en System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId) 
    en System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto) 
    en System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration) 
    en System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration) 
    en System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) 
    en System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) 
    en System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) 
    en System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b() 
    en System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) 
    en System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) 
    en System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) 
    en System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) 
    en System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run() 
    en System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    en System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    en System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    en System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force) 
    en System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0() 
    en System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
AlterProcedureOperation 

Moja kontekst jest:

[DbConfigurationType(typeof(MySqlEFConfiguration))] 
    public class GiveAndGetContext : DbContext 
    { 

     public GiveAndGetContext() 
     : base("GiveAndGetContext") 
     { 
      //Database.SetInitializer(
      //  new MigrateDatabaseToLatestVersion<GiveAndGetContext, DAL.Migrations.Configuration>("GiveAndGetContext")); 

     } 


     //Para crear des de presentation 
     // // Constructor to use on a DbConnection that is already opened 
     // public GiveAndGetContext(DbConnection existingConnection, bool contextOwnsConnection) 
     //: base(existingConnection, contextOwnsConnection) 
     // { 

     // } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      base.OnModelCreating(modelBuilder); 
      modelBuilder.Entity<Category>().MapToStoredProcedures(); 
      modelBuilder.Entity<City>().MapToStoredProcedures(); 
      modelBuilder.Entity<Controller>().MapToStoredProcedures(); 
      modelBuilder.Entity<Country>().MapToStoredProcedures(); 
      modelBuilder.Entity<Interest>().MapToStoredProcedures(); 
      modelBuilder.Entity<Item>().MapToStoredProcedures(); 
      modelBuilder.Entity<Language>().MapToStoredProcedures(); 
      modelBuilder.Entity<Literal>().MapToStoredProcedures(); 
      modelBuilder.Entity<Province>().MapToStoredProcedures(); 
      modelBuilder.Entity<Region>().MapToStoredProcedures(); 
      modelBuilder.Entity<User>().MapToStoredProcedures(); 
      modelBuilder.Entity<View>().MapToStoredProcedures(); 
      modelBuilder.Entity<prueba>().MapToStoredProcedures(); 
     } 
} 
} 

Configuration file of migrations is: 

internal sealed class Configuration : DbMigrationsConfiguration<DAL.Context.GiveAndGetContext> 
    { 
     public Configuration() 
     { 
      AutomaticMigrationsEnabled = false; 

      SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator()); 

     } 

Mój plik package.config jest:

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="EntityFramework" version="6.1.3" targetFramework="net46" /> 
    <package id="MySql.Data" version="6.9.8" targetFramework="net46" /> 
    <package id="MySql.Data.Entity" version="6.9.8" targetFramework="net46" /> 
</packages> 

i Przykład pliku dodatek migracji jest:

using System; 
    using System.Data.Entity.Migrations; 

    public partial class _2 : DbMigration 
    { 
     public override void Up() 
     { 
      AlterColumn("dbo.pruebas", "Name", c => c.Short(nullable: false)); 
      AlterStoredProcedure(
       "dbo.prueba_Insert", 
       p => new 
        { 
         IdController = p.Short(), 
         Name = p.Short(), 
        }, 
       body: 
        @"SET SESSION sql_mode='ANSI';INSERT INTO `pruebas`(
         `IdController`, 
         `Name`) VALUES (
         @IdController, 
         @Name); 
         SELECT 
         `Id` 
         FROM `pruebas` 
         WHERE row_count() > 0 AND `Id`=last_insert_id();" 
      ); 

      AlterStoredProcedure(
       "dbo.prueba_Update", 
       p => new 
        { 
         Id = p.Short(), 
         IdController = p.Short(), 
         Name = p.Short(), 
        }, 
       body: 
        @"UPDATE `pruebas` SET `IdController`[email protected], `Name`[email protected] WHERE `Id` = @Id;" 
      ); 

     } 

     public override void Down() 
     { 
      AlterColumn("dbo.pruebas", "Name", c => c.String(unicode: false)); 
      throw new NotSupportedException("Scaffolding create or alter procedure operations is not supported in down methods."); 
     } 
    } 

Mogę utworzyć bazę danych z komendami i dodać nową tabelę, ale nie mogę zmodyfikować kolumny tabeli (upuścić kolumnę lub dodać kolumnę). Problem nie jest kropla, to jest metoda AlterStoredProcedure.

Odpowiedz

0

Twój Wyjątkiem jest: "System.NotImplementedException: AlterProcedureOperation"

I to byłem found:

Zapoznaj się strona podręcznika dla przechowywanych procedur ...

„ALTER PROCEDURY | FUNCTION może modyfikować tylko komentarz charakterystyczny i przechowywaną procedurę lub funkcję.Jednak nie można zmienić parametrów lub treści procedury przechowywanej za pomocą tej instrukcji; do dokonać takich zmian, należy upuścić i ponownie utworzyć procedurę przy użyciu PROCEDURY DROP i CREATE PROCEDURE. "

Więc spróbuj zmienić migrację do DROP i STWÓRZ zamiast ALTER