FluentMigrator - 执行资源 file/script
FluentMigrator - Execute resource file/script
我尝试使用 FluentMigrator 迁移我的一个数据库。
其中一个迁移尝试执行脚本。
我想:“我只想将 DLL 发送给我的同事”
所以我将 SQL-Script 作为资源文件打包到 DLL 中,现在尝试访问它,但似乎找不到脚本。
迁移
[Migration(201506021451)]
public class M116_Init_RoleManagement : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Role")
.WithIdColumn()
.WithColumn("Name").AsString().NotNullable();
Insert.IntoTable("Role").Row(new { Name = "Administrator" });
Insert.IntoTable("Role").Row(new { Name = "Manager" });
Insert.IntoTable("Role").Row(new { Name = "SalesManager" });
Insert.IntoTable("Role").Row(new { Name = "Employee" });
Create.Table("EmployeeRole")
.WithIdColumn()
.WithColumn("EmployeeId").AsInt64().NotNullable()
.WithColumn("RoleId").AsInt64().NotNullable();
Execute.Script(Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles);
}
}
资源文件
项目结构
错误
201506021451: M116_Init_RoleManagement migrating =========================
Beginning Transaction
Rolling back transaction
Illegal Sign in Path
答案很明显:
通过 Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles
访问资源文件
returns 的内容而不是文件的路径。
所以调用应该看起来像
[Migration(201506021451)]
public class M116_Init_RoleManagement : ForwardOnlyMigration
{
public override void Up()
{
.
.
.
Execute.Sql(Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles);
}
}
我尝试使用 FluentMigrator 迁移我的一个数据库。 其中一个迁移尝试执行脚本。 我想:“我只想将 DLL 发送给我的同事” 所以我将 SQL-Script 作为资源文件打包到 DLL 中,现在尝试访问它,但似乎找不到脚本。
迁移
[Migration(201506021451)]
public class M116_Init_RoleManagement : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Role")
.WithIdColumn()
.WithColumn("Name").AsString().NotNullable();
Insert.IntoTable("Role").Row(new { Name = "Administrator" });
Insert.IntoTable("Role").Row(new { Name = "Manager" });
Insert.IntoTable("Role").Row(new { Name = "SalesManager" });
Insert.IntoTable("Role").Row(new { Name = "Employee" });
Create.Table("EmployeeRole")
.WithIdColumn()
.WithColumn("EmployeeId").AsInt64().NotNullable()
.WithColumn("RoleId").AsInt64().NotNullable();
Execute.Script(Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles);
}
}
资源文件
项目结构
错误
201506021451: M116_Init_RoleManagement migrating ========================= Beginning Transaction
Rolling back transaction
Illegal Sign in Path
答案很明显:
通过 Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles
访问资源文件
returns 的内容而不是文件的路径。
所以调用应该看起来像
[Migration(201506021451)]
public class M116_Init_RoleManagement : ForwardOnlyMigration
{
public override void Up()
{
.
.
.
Execute.Sql(Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles);
}
}