C# Migratordotnet创建初始迁移
我正在尝试使用现有的数据库。我的数据库有大约100个表,我正在尝试生成初始迁移 我试过使用C# Migratordotnet创建初始迁移,c#,database,database-migration,migratordotnet,C#,Database,Database Migration,Migratordotnet,我正在尝试使用现有的数据库。我的数据库有大约100个表,我正在尝试生成初始迁移 我试过使用 C:\migrations>Migrator.Console.exe SqlServer "Data Source=.\sqlexpress;Initial Catalog=my_database;Integrated Security = True;" MigracijeBaze.dll -dump InitialMigration.cs 不幸的是,生成的迁移具有typeof(string)的每
C:\migrations>Migrator.Console.exe SqlServer "Data Source=.\sqlexpress;Initial Catalog=my_database;Integrated Security = True;" MigracijeBaze.dll -dump InitialMigration.cs
不幸的是,生成的迁移具有typeof(string)的每一列。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)),
);
我做错什么了吗?进行初始迁移的最佳实践是什么?我找到了答案。我已经下载了源代码并使用了调试器。 看起来dump选项并没有完全实现
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();
}
公共虚拟列[]GetColumns(字符串表)
{
列表列=新列表();
使用(
IDataReader阅读器=
行刑(
Format(“select COLUMN_NAME,可从信息_schema.columns中为空,其中table_NAME='{0}',table)))
{
while(reader.Read())
{
Column Column=新列(reader.GetString(0),DbType.String);
字符串nullableStr=reader.GetString(1);
bool isNullable=nullableStr==“是”;
column.ColumnProperty |=isNullable?ColumnProperty.Null:ColumnProperty.NotNull;
列。添加(列);
}
}
返回columns.ToArray();
}
数据库类型是硬编码的。我将为我的第一次迁移调用sql脚本。相关问题是