1
votes

I try migrate one of my databases with FluentMigrator. One of the migrations tries to execute a script. I thought: "I only want to send the DLL to my colleagues" So I packed the SQL-Script into the DLL as a resource-file and now try to access it, but it seems like the Script is not found.

Migration

[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);
    }
}

Resource File ResourceFile

Projectstructure

ProjectExplorer

Error

201506021451: M116_Init_RoleManagement migrating ========================= Beginning Transaction

Rolling back transaction

Illegal Sign in Path

1

1 Answers

2
votes

The Answer is pretty obvious: Accessing the resource-file via Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles returns the content of and not the path to the file.

So the call should look like

[Migration(201506021451)]
public class M116_Init_RoleManagement : ForwardOnlyMigration
{
    public override void Up()
    {
        .
        .
        . 
        Execute.Sql(Hsk.Migrations.Properties.Resources._2015021451_CreateSalesManagerRoles);
    }
}