Migratordotnet创建初始迁移

时间:2010-11-05 07:43:30

标签: c# database database-migration migratordotnet

我正在尝试将migratordotnet用于现有数据库。我的数据库有大约100个表,我正在尝试生成初始迁移。

我尝试过使用

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

不幸的是,生成的迁移每列都有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)),
);

我做错了吗?进行初始迁移的最佳做法是什么?

1 个答案:

答案 0 :(得分: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

相关问题