Sharing models between Windows Phone and Windows 8: An exercise in futility

Data access is hell.

I’ve been stuck on the same problem for a while now, working on MoodTracker. The problem comes down to SQL Server Compact and LINQ to SQL, and the lack of the former on Windows 8. You see, I’d like to get MoodTracker on Windows 8. However, to do so means reworking how the app does data access since SQL CE isn’t available for use in Windows 8 applications, and unfortunately, there’s absolutely no useful guidance on moving from using SQLCE-decorated model classes to a more portable solution for data access.

So here I am, working on separating my model classes from the concern of data access. And it’s not going too well. Sure, I have a portable library containing new model classes free of the attributes and various association-related classes, and I’ve moved the SQLCE-specific stuff into its own assembly. But that’s as far as things have gone. Trying to connect the dots between the model classes and the data access classes has gotten me nowhere. On a related issue, working out how to inject the DAL into the app had been troubling me, but the realization that it would be done in another platform-specific assembly has given me the clue to work that out (so long as I can work out an interface for data access that works).

I really wish there was some guidance on this, so that phone apps making use of a local database could be more easily ported to Windows 8, with a lot less fuss. If anyone has a good solution for this problem (bonus points if it’s MvvmLight friendly) please let me know!

  • ada

    Can you explain in more details about how you’ve implemented below. I have similar issue but I am adding database capability into Portable Library for WP8 which is being shared by a WPF app..

    Sure, I have a portable library containing new model classes free of the attributes and various association-related classes, and I’ve moved the SQLCE-specific stuff into its own assembly.

    • http://about.me/chris.charabaruk Chris Charabaruk

      Pretty much the only thing I can suggest is maintaining two different sets of classes for your app data — one being the portable model classes and the other being database model classes in the platform-specific assemblies. If you’re fortunate you should be able to derive the database-specific classes from the portable ones, but more likely you’ll need to use the DB classes for temporary objects when moving data in or out of the database.