How do I setup a ROWVERSION/TIMESTAMP datatype column using FluentMigrator?
Asked Answered
A

1

7

I am trying to use the ROWVERSION (or TIMESTAMP) datatype on a SQL Server table for optimistic concurrency control.

My table is setup using FluentMigrator and I do not know how to get the datatype I need. According to Microsoft's article on ROWVERSION, a nonnullable ROWVERSION column is semantically equivalent to a binary(8) column; the nullable ROWVERSION datatype is equivalent to a varbinary(8).

Here is an example and as close as I can get...

public override void Up()
    {
        Create.Table("Test")
            .WithColumn("Id").AsInt32().Identity().PrimaryKey()
            .WithColumn("Description").AsAnsiString(255)
            .WithColumn("RowVersion").AsBinary(8).NotNullable(); 
    }

.WithColumn("RowVersion").AsBinary(8).NotNullable(); is the line I can't figure out... There is no .AsRowversion or .AsTimestamp option.

Thanks in advance!

Agitator answered 30/5, 2012 at 19:27 Comment(1)
I don't know FluentMigrator, sorry. But FluentNHibernate has a method Version(x => x.VersionProperty) in ClassMap<T>, that enables NHibernate optimistic locking (the property can be any of any integer type or DateTime). Is there nothing similar in FluentMigrator?Kiser
A
15

Wow! How something can be so simple that I look right over the obvious...

.WithColumn("Version").AsCustom("rowversion").NotNullable();
Agitator answered 30/5, 2012 at 20:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.