Over a million developers have joined DZone.

Migrations in C# using RikMigrations

DZone's Guide to

Migrations in C# using RikMigrations

· ·
Free Resource

For those of you who have used Ruby on Rails before, you most likely already know what migrations are, and you probably love them! They are such a simple idea and once you start using them you'll wonder why you never thought of them. Recently I was doing a bit of work which required me to do some build automation, and (after prodding from some co-workers) I decided that we needed to do some migrations. Migrations are easier to just show you than explain, so I am going to move right into some code. First though, I am going to explain to you the tool that I chose.

I searched around a bit, and found two different tools for doing Migrations in .NET. One was called MigratorDotNet and the other was called RikMigrations. I evaluated them both, and in the end I chose RikMigrations because I liked the way that it searched an assembly for embedded migrations (instead of pointing to a folder of source files) and also allowed you to have multiple sets of Migrations in the same project by identifying them with keys. I'm assuming that this could have been accomplished in MigratorDotNet by using multiple folders, but I chose not to take that approach.

Okay, so let's see some code. First we are going to start off by creating a blank database called "TestMigratorApp". Next I am going to pretend that I have received a requirement for creating a user table with just two columns. One for "Id" which is going to be an auto-incrementing integer column, and another for username. Obviously our user table would be a bit more complex than this, but we don't want to clutter the example with too much extra crap.

Read the rest of this post at CodeThinked.com


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}