Microsoft MVP - Orchard CMS Web Developer

RSS Twitter Google+

David Hayden

Husband, Father, Web Developer in Sarasota, FL.

Latest tweets
Quick tip on using WorkContext.CurrentTheme and Html.ThemePath in Orchard CMS. http://t.co/9M8c4ke9 #orchardcms
JetBrains released dotPeek 1.0, their Free .NET decompiler and assembly browser. http://t.co/O65OqcLQ
Amazon Web Services now supports SQL Server and .NET Applications. http://t.co/nNZSd9Z9
After many hours of KoA and Skyrim, I need to find a new RPG for me and the kids. Thinking an older one - Dragon Age: Origins.
Orchard 1.4.1 Released! Download: http://t.co/KDphWq7U Blog Post: http://t.co/MnVvVhHh #orchardcms
Donating my remaining 103 .NET and Software Development books to local public library today. Hope they make a difference!

Orchard and SchemaBuilder AlterTable and AlterColumn

I took a few minutes to update an Orchard Module I use on DavidHayden.me to display various thoughts on my blog. In the Migration.cs file I wanted to change the size of the Note Column from 500 characters to 2000 characters, because I wanted to add HTML to the Note Field for links, etc. I could have made it unlimited, but I didn't want the notes to become like blog posts so I thought 2000 was a fair number to display a thought and include some basic HTML. If you are familiar with altering a table column in Orchard CMS, you know this takes you into the Migration.cs file of the module and the joys of using SchemaBuilder to alter the table and column.

My first attempt to change the string column from 500 characters to 2000 characters was unsuccessful as I figured I could just use the WithLength(2000) with SchemaBuilder.AlterTable to adjust the length of the column. Doing so kept giving me a cryptic error that I must specify the column type when trying to adjust its length. After a little digging it turns out I need to use WithType to adjust the length of the column in the Orchard CMS Table.

In my Orchard Module's Migration.cs file I added the following entry to change the length of the column from 500 to 2000 using SchemaBuilder.AlterTable and AlterColumn:

public int UpdateFrom1() {
   SchemaBuilder.AlterTable("NoteRecord", table => table
        .AlterColumn("Note", c => c.WithType(DbType.String, 2000))
    );
            
    return 2;
}

With this change I now have enough room to put some basic HTML in my Note Field.

I hope you enjoyed this simple tip on using SchemaBuilder.AlterTable and AlterColumn to change the length of a column in Orchard CMS.

© Copyright 2012 David Hayden. All rights reserved.
Up