2010-11-05 167 views
2

我正在嘗試使用現有數據庫的migratordotnet。我的數據庫有大約100個表格,我正在嘗試生成初始遷移。Migratordotnet創建初始遷移

我使用

C:\migrations>Migrator.Console.exe SqlServer "Data Source=.\sqlexpress;Initial Catalog=my_database;Integrated Security = True;" MigracijeBaze.dll -dump InitialMigration.cs 

Unfortinutely嘗試,產生的遷移與typeof運算(字符串)每一列。 Int,DateTime,Decimal列轉換爲字符串。 例如,對於表Godine

CREATE TABLE [dbo].[Godine](
    [ID] [int] IDENTITY(1,1) NOT NULL, 
    [FirmaID] [nvarchar](2) NOT NULL, 
    [Godina] [int] NOT NULL, 
    [BazaSifri] [nvarchar](50) NOT NULL, 
    [BazaPodataka] [nvarchar](50) NOT NULL, 
CONSTRAINT [PK_Godine] PRIMARY KEY CLUSTERED 
(
    [ID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

產生遷移

Database.AddTable("Godine", 
    new Column("ID", typeof(String)), 
    new Column("FirmaID", typeof(String)), 
    new Column("Godina", typeof(String)), 
    new Column("BazaSifri", typeof(String)), 
    new Column("BazaPodataka", typeof(String)), 
); 

難道我做錯了什麼?進行初始遷移的最佳做法是什麼?

回答

2

我找到了答案。我已經下載了源代碼並使用了調試器。 看來,轉儲選項沒有完全實現。

public virtual Column[] GetColumns(string table) 
{ 
    List<Column> columns = new List<Column>(); 
    using (
     IDataReader reader = 
      ExecuteQuery(
       String.Format("select COLUMN_NAME, IS_NULLABLE from information_schema.columns where table_name = '{0}'", table))) 
    { 
     while (reader.Read()) 
     { 
      Column column = new Column(reader.GetString(0), DbType.String); 
      string nullableStr = reader.GetString(1); 
      bool isNullable = nullableStr == "YES"; 
      column.ColumnProperty |= isNullable ? ColumnProperty.Null : ColumnProperty.NotNull; 

      columns.Add(column); 
     } 
    } 

    return columns.ToArray(); 
} 

數據庫類型是硬編碼的。我將只爲第一次遷移調用sql腳本。相關問題是on the issue tracker