Is it possible to call the fluent expression methods while inside the action that I pass to Execute.WithConnection? I am trying to use Insert.IntoTable and get a null reference exception thrown from line 36 of FluentMigrator\Builders\Insert\InsertExpressionRoot.cs - it appears that the _context variable may be null at this point I am having a difficult time understanding why this is.
What I am trying to do is select some data so that I may manipulate it in c#, as that is easier than manipulating it in T-SQL, and use the result of my c# operations to update the data or insert new data (to be more specific, I need to pick one query string parameter out of a stored url string and insert it somewhere else).
The only way I see to select data within a migration is to use Execute.WithConnection, but if I try to use any fluent migrator expression I get this null reference exception (when testing Create.Table, e.g., it occurs on line 49 of FluentMigrator\Builders\Create\CreateExpressionRoot.cs).
Here's a simple code example of what I'm trying to do, the null reference exception is thrown from the line in CustomDml that calls Insert.IntoTable:
[Migration(1)]
public class MyMigration : Migration
{
public void Up() {
Execute.WithConnection(CustomDml);
public void CustomDml(IDbConnection conn, IDbTransaction tran)
var db = new NPoco.Database(conn).SetTransaction(tran); // NPoco is a micro-ORM, a fork of PetaPoco
var records = db.Fetch<Record>("-- some sql");
foreach (var r in records) {
var newValue = Manipulate(r.OriginalValue);
Insert.IntoTable("NewRecords").Row(new { OriginalValueId = r.Id, NewValue = newValue });
Any help would be appreciated. Perhaps there is disagreement on whether DML is appropriate in a migration, and I am open to suggestions, but this scenario has come up twice this week alone. For now I am simply performing the insert using my micro-ORM within the action rather than FluentMigrator and that does work. Thanks.