Mobile Zone is brought to you in partnership with:

David has posted 32 posts at DZone. View Full User Profile

Two Ways to Create a Database for Your Mango App

  • submit to reddit

So you are working on a Windows Phone 7 App and need to create a database to store application data.  There are plenty of resources out there to help you get started, but this recent Mango Database tutorial by Jerry Nixon, a Microsoft Developer Evangelist, is particularly clear, to the point, and chock full of useful external resources.

Part 1 will flex your SQL chops as you utilize the Entity Framework's Code First development pattern to create your classes first, so that they can then be mapped onto an existing database or used to generate a fresh database schema.  Don't forget to take advantage of the "Do better" sections to optimize what you've put together.  For example, Jerry has the following advice for efficiently dealing with frequent queries:

One of the easiest ways to optimize the performance of an update operation on a table is to add a version column. This optimization is specific to LINQ to SQL for Windows Phone. This can yield a significant performance improvement for large updates. More here.


Jerry is approaching this tutorial like a true educator.  How do I know?  At the end of the post he puts himself in the student's shoes and launches a preemptive strike against the questions his lesson is likely to raise.  For each question you'll find a link to the relevant information straight from Microsoft.

Part 2 of the tutorial approaches the same project from a different angle.  Rather than the Code First method, you can opt to use Visual Studio create the database first.  According to Jerry, this method is more intuitive at design-time but unfortunately requires you to jump through some hoops:

It seems most intuitive to use the database visual designer at design-time. It is most unfortunate that this method is the least supported. Moreover, it seems just messy that we must drop to the Visual Studio DOS prompt and use SQLMetal to get it fully working.

If you're working on a Windows Phone app, this tutorial is a great resource not only for producing results but also for getting you to think about methodologies.  Whether you prefer to code first or design first, Jerry's got you covered. 


source for part 1:

source for part 2:

Published at DZone with permission of its author, David Pell.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Jerry Nixon replied on Thu, 2011/11/17 - 11:17am

One thing I think a lot of developers do not realize is if they are using the free version of Visual Studio 2010 (Visual Studio 2010 Express) to build Windows Phone applications the second option (using Server Explorer to visually build your database) is not for them. This is because Server Explorer is not part of Express.

That means that code-first is the prescribed method for users of Visual Studio Express.

However, developers can skin this cat another way. Many developers don't know about SQL Server Management Express - another great, free tool allowing developers to create SQL Server Compact databases visually (as if they had Server Explorer). It's perhaps one extra step, but offers developers using free tools the same rich experience - which is great.

Here's the link to SQL Server Management Express:

  • One final note is that there is a follow-up post to my two posts you noted in your article. I wanted to point readers to it. It discusses how to use the SQL Server Compact Toolbox to create the Linq to SQL Data Context in your Windows Phone project. It's a nice UI-approach to the SQL Metal command line.

    Here's the link to that third article:

  • // Jerry Nixon

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.