Search code examples
xmlmigrationnotsupportedexception

FluentMigrator NotSupportedException - Mapping XML Column


I'm using FluentMigrator in a project and I'm having some trouble with an update in database when I try to add a new xml column in a existing table.

I'm using:

  • FluentMigrator 1.3.1.0
  • FluentMigrator.Tools 1.3.1.0
  • SQL Server 2014
  • .Net Framework 4.5

The migrator is configured by using SqlServer2012ProcessorFactory.

In one of my migrations, I have this code below:

[Migration(201502271030)]
public class _201502271030_AddLineItemAndSummariesColumn : Migration
{
    public override void Up()
    {
        Create.Column("InitialDiscount").OnTable("LineItems").InSchema(Const.Schema.DeskReview)
            .AsDecimal(11, 2).Nullable().WithDefaultValue(false);
        Create.Column("AcceptedDiscount").OnTable("LineItems").InSchema(Const.Schema.DeskReview)
            .AsDecimal(11, 2).Nullable().WithDefaultValue(false);
        Create.Column("BodyshopName").OnTable("LineItems").InSchema(Const.Schema.DeskReview)
            .AsString(Const.Length.Name).Nullable().WithDefaultValue(false);
        Create.Column("State").OnTable("LineItems").InSchema(Const.Schema.DeskReview)
            .AsString(Const.Length.Name).Nullable().WithDefaultValue(false);
        Create.Column("City").OnTable("LineItems").InSchema(Const.Schema.DeskReview)
            .AsString(Const.Length.Name).Nullable().WithDefaultValue(false);

        Create.Column("ExternalDataXml").OnTable("WorkQueueItems").InSchema(Const.Schema.DeskReview)
            .AsXml(int.MaxValue).Nullable().WithDefaultValue(false);
        Create.Column("Version").OnTable("WorkQueueItems").InSchema(Const.Schema.DeskReview)
            .AsInt32().Nullable().WithDefaultValue(0);
    }

    public override void Down()
    {

    }
}

But, when I run this code, I got this Exception:

Exception Details: System.NotSupportedException: Unsupported DbType 'Xml'

Line 15:             try
Line 16:             {
Line 17:                 base.ApplyMigrationUp(migrationInfo, useTransaction);
Line 18:             }
Line 19:             catch (Exception e)

Anyone ever had this problem or knows what is wrong?


Solution

  • The problem was: I was trying to specify the XML max length with this:

    .AsXml(int.MaxValue)
    

    on:

    Create.Column("ExternalDataXml").OnTable("WorkQueueItems").InSchema(Const.Schema.DeskReview)
            .AsXml(int.MaxValue).Nullable().WithDefaultValue(false);
    

    I just removed the parameter and it worked.

    So, the code stayed like this:

    Create.Column("ExternalDataXml").OnTable("WorkQueueItems").InSchema(Const.Schema.DeskReview)
                .AsXml().Nullable();
    

    what a dumb problem... but ok.