WindowsPhoneGeek

WPAppInfo

Login | Join (Why?)

rss rss rss
logo

Something to watch for with DatabaseSchemaUpdater

1/30/2012

source: cfield.tumblr.com

Local databases on Windows Phone 7.5 are a wonderful thing. They allow you to write beautiful code that takes full advantage of LINQ, and who doesn't like LINQ right?!? (answer: crazy people). But, using databases doesn't come without it's headaches, and a common one is how you update it.

Fortunately several clever people have already come up with a way of updating your database schema that involve using the DatabaseSchemaUpdater. In a nutshell that process involves something like this:

if (dbSchemaUpdater.DatabaseSchemaVersion < 1) {
     dbSchemaUpdater.AddColumn<MyTable1>("NewColumn1")
}
if (dbSchemaUpdater.DatabaseSchemaVersion < 2) { 
     dbSchemaUpdater.AddColumn<MyTable1>("NewColumn2")
}
dbSchemaUpdater.DatabaseSchemaVersion = 2;
dbSchemaUpdater.Execute(); 

This works really well for most circumstances. However, there is a circumstance where by you can trip up as a developer. Consider that we release our app and it has a DatabaseSchemaVersion of 2. It's great, everyone loves it, so we start work on an update with extra awesome in it.

...Read more

You can also follow us on Twitter @winphonegeek

Comments

Add comment to 'Something to watch for with DatabaseSchemaUpdater'

Comment

New! WindowsPhoneGeek Component Marketplace

Our Top Articles & Free books

Our Top Tips & Samples