2012-11-21 17 views
1

我已經設置實體框架4.4.0(EF5)代碼第一次遷移爲MySql數據庫,但是當我運行Add-Migration命令時,我總是得到dbo前置在表名,像這樣:實體框架4.4.0代碼第一次遷移MySql不斷添加dbo到新表

CreateTable(
      "dbo.Fields", 
      c => new 
       { 
        FieldId = c.Int(nullable: false, identity: true), 
        FieldTypeId = c.Int(nullable: false), 
        Name = c.String(nullable: false, unicode: false), 
        Description = c.String(unicode: false), 
        CodeList = c.String(unicode: false), 
        Mask = c.String(unicode: false), 
       }) 
      .PrimaryKey(t => t.FieldId) 
      .ForeignKey("dbo.FieldTypes", t => t.FieldTypeId, cascadeDelete: true) 
      .Index(t => t.FieldTypeId); 

我使用Devart數據庫提供商和我的遷移配置類看起來是這樣的:

internal sealed class Configuration : DbMigrationsConfiguration<mydbcontext> 
{ 
    public Configuration() 
    { 
     // Create a custom connection to specify the database and set a SQL generator for MySql. 
     var connectionInfo = 
      MySqlConnectionInfo.CreateConnection("<<myconnectionstring>>"); 

     TargetDatabase = connectionInfo; 

     SetSqlGenerator(connectionInfo.GetInvariantName(), new MySqlEntityMigrationSqlGenerator()); 

     var config = MySqlEntityProviderConfig.Instance; 
     config.Workarounds.IgnoreSchemaName = true; 

     AutomaticMigrationsEnabled = false; 
    } 

    protected override void Seed(CloudDataSetDbContext context) 
    { 

    } 
} 

出於某種原因,IgnoreSchemaName = true時不考慮。

我說,像這樣的Devart數據庫提供商的web.config文件:

<system.data> 
<DbProviderFactories> 
    <remove invariant="Devart.Data.MySql" /> 
    <add name="dotConnect for MySQL" invariant="Devart.Data.MySql" description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql, Version=6.80.350.0, Culture=neutral, PublicKeyToken=09af7300eec23701" /> 
</DbProviderFactories> 

而且我還添加了一個組裝重定向,因爲Devart需要這個,像這樣:

<dependentAssembly> 
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" /> 
    <bindingRedirect oldVersion="4.3.1.0" newVersion="4.4.0.0" /> 
    </dependentAssembly> 

有人可以幫我嗎? Thx, Steven。

回答

0

在調用SetSqlGenerator之前嘗試配置它們的Singleton配置選項。我有一個詭異的想法,他們會使用當前的設置,因爲它們是在生成器設置時的情況,之後改變它們不會改變生成器的行爲。

0

我們不影響代碼生成遷移內容(代碼生成由Microsoft完成)。 我們根據遷移代碼生成DDL。生成DDL時,代碼中指定的「dbo」模式名稱將被忽略。

+1

Thx爲信息。 同時我通過將DotConnect升級到版本7.2.122來得到它的工作。 –

+0

我們很高興聽到問題得到解決。 – Devart

0

我通過將DotConnect升級到新的7.2.122版本解決了問題。 現在__Migrations表格在其前面沒有dbo的情況下被創建,因此插入語句起作用。

相關問題