Mobile World

Perst - a database for Windows Phone 7 Silverlight

Download Source Code    **UPDATED for Beta libraries 21st July 2010**

There has been some comment about the lack of a client side database for Windows Phone 7 Silverlight. Windows Phone 7 does have SQL Server Compact Edition installed in the OS image, but in the initial release, it is there to support the built-in apps only and has no public API to allow Silverlight developers to use it for data persistence.

However, there is a database available that WP7 Silverlight developers can use: it's called Perst .NET which is developed by McObject and the source code is pure C# and freely downloadable. As distributed, it works fine with the full .NET Framework, with the .NET Compact Framework and with desktop Silverlight, and they have a demo app of a CRM that runs in the desktop browser in Silverlight (read about it here). Using Perst for .NET, developers using Silverlight can now include true database management system features in their Silverlight applications, including adding persistence to this data by storing it in a container file in isolated storage.

 I thought it would be fun to see if I could port the database and implement the CRM app on Windows Phone 7 and it wasn't too hard!

Perst Contacts ListPerst Contacts List

Here you can see the contacts list, and the details view when you select a contact from the list.

You can download the full source code from the link at the top of this post (developed with the Windows Phone 7 April Devtools refresh that you can download here) . Inside it you will find three projects:

  • PerstWP7 - this is a Windows Phone 7 port of the database code. It doesn't have the replication code in it that the full .NET framework version supports, and it doesn't have a few methods in the database wrapper that require IQueryable, which is not supported on WP7.
  • PerstDemo - This is the source code for the CRM app. This is a work in progress! At present, the app allows you to generate test data to fill the database, allows you to list, add, edit, delete and search Contacts. At present there is no UI to allow you to work with Leads and Activities, as the full Silverlight CRM demo app does, but I plan to add this over the coming months, perhaps using a panoramic view which would be nice!
  • SilverlightToolkit.Controls.Input - Although according to blog posts such as this you are supposed to be able to use the Silverlight Toolkit libraries directly - at least for some of the controls in there - I couldn't get it to work with the current drop of the WP7 dev tools. I wanted an AutoSuggestTextbox to use in the search function, so I extracted the source for the toolkit version of this control and compiled it into this WP7 class library.

Using the App

When you start the app, you'll just see an empty heading of Contacts. Click the ellipses on the menu bar to reveal the menu for generating test data. Use the slider to select the total number of Contact, Lead and Activity objects to generate: for example, 5000 will give you a long list of a few hundred contacts.

Perst CRM MenuGenerate Data SliderGenerate Data Committing

As you play with the app, you'll see that you can view and edit details of Contacts in the list, you can delete contacts and you can add new contacts by tapping the '+' icon at the foot of the main screen.

Full Text Search

'Well, is this really a database?' you might be asking. Well - how about this: it's got a Full Text Search facility! Perst Full Text search If you tap on the Search icon on the menu bar, you get a Search box appear, which is the AutoSuggestTextBox. As you enter characters into the search box, it displays a list of contacts that match as you type in a drop down list. You can select a contact from the dropdown, or just display a subset of contacts that include the search string in any of the Full Text Search index fields, which are LastName, FirstName and CompanyName.

 

Using Perst for Commercial Use.

One point to make about this: Perst is free to use for non-commercial use and is released under the GPL license. Perst is cross-platform as there is a Java version as well as the .NET one, and Perst is already used in J2ME and on Android. If you want to use it in a commercial app, then a license fee applies which should only amount to a few pennies per copy.   If you are in the UK, you can talk to MPC Data who distribute Perst to that market. I don't know about other markets so I suggest you contact McObject.

Next Steps

Over the next few days I will follow up with a few posts showing how you write code to work with a Perst database. In the meantime, please download the sample code and take a look at how it works.

In this sample, we are using Perst's database wrapper which gives relational database-like behaviour so you create tables and keys and store and retrieve objects from tables in a manner that will be familiar to anyone who has worked with relational databases before. However, Perst is actually an object database, and if you don't use the database wrapper, you simply work with .NET classes in exactly the same way an any other .NET object, but it just so happens that these objects have the ability to be persisted. That's really interesting to me as I hate writing all that unnecessary object relational mapping (ORM) code to convert objects to and from their database format. However, that's a topic for another day.

Over time, I plan on extending this sample to add the UI for working on Leads and Activities as well - it's a learning exercise for me to really learn WP7 development in depth, and hopefully will be of interest to you too!

Perst - a database for Windows Phone 7 Silverlight - Part 2


Posted Jun 07 2010, 06:10 AM by Andy Wigley

Comments

Twitter Trackbacks for Perst - a database for Windows Phone 7 Silverlight - Andy Wigley - APPA Mundi [appamundi.com] on Topsy.com wrote Twitter Trackbacks for Perst - a database for Windows Phone 7 Silverlight - Andy Wigley - APPA Mundi [appamundi.com] on Topsy.com
on 06-07-2010 9:01

Pingback from  Twitter Trackbacks for                 Perst - a database for Windows Phone 7 Silverlight - Andy Wigley - APPA Mundi         [appamundi.com]        on Topsy.com

Mobility Digest - Windows Phone - Another Method To Get Databases In WP7 wrote Mobility Digest - Windows Phone - Another Method To Get Databases In WP7
on 06-09-2010 21:58

Pingback from  Mobility Digest - Windows Phone -   Another Method To Get Databases In WP7

Andy Wigley wrote Perst - a database for Windows Phone 7 Silverlight - Part 2
on 06-13-2010 11:48

In this post, I explain some of the key logic in the Perst sample showing how to create a database and

Many Niches » Blog Archive » Windows Phone 7 Device Requests wrote Many Niches » Blog Archive » Windows Phone 7 Device Requests
on 06-17-2010 20:58

Pingback from  Many Niches » Blog Archive   »  Windows Phone 7 Device Requests

Matthijs Hoekstra wrote Windows Phone 7 Developer devices
on 06-25-2010 5:53

Op TechEd heeft men aangekondigd dat je kon aangeven dat je geïnteresseerd bent in een Windows Phone

Mc Object Offers Perts Embedded Database For Microsoft Windows Phone 7 | MobileTechWorld wrote Mc Object Offers Perts Embedded Database For Microsoft Windows Phone 7 | MobileTechWorld
on 06-30-2010 8:00

Pingback from  Mc Object Offers Perts Embedded Database For Microsoft Windows Phone 7 | MobileTechWorld

Open Source Databases for Windows Phone 7 « Development « Chris Koenig wrote Open Source Databases for Windows Phone 7 « Development « Chris Koenig
on 06-30-2010 14:53

Pingback from  Open Source Databases for Windows Phone 7 « Development « Chris Koenig

Windows Phone 7 gets database management « Toys and Gadget - gizmo, toys, gadget and all that stuff wrote Windows Phone 7 gets database management « Toys and Gadget - gizmo, toys, gadget and all that stuff
on 06-30-2010 20:44

Pingback from  Windows Phone 7 gets database management «  Toys and Gadget - gizmo, toys, gadget and all that stuff

Windows Phone 7gets open source database... wrote Windows Phone 7gets open source database...
on 07-07-2010 6:36

Pingback from  Windows Phone 7gets open source database...

Copyright © 2010 APPA Mundi Limited. All Rights Reserved. Terms of Use and Privacy Policy.