In addition to my last post about how to use SQLite on Windows Phone 8, I made today a small sample how to use a data access layer for SQLite across several platforms (Windows Phone 8 and Windows 8).
The pain is – as I mentioned in my last post – that we cannot use the same SQLite database engine for both platforms. Therefore the sharing of the data access classes is for example possible via linking the same code classes in separates data layer libraries:
To capsulate the data classes, which is possible by using the new portable library type in Visual Studio, you have to use a little “dirty” trick. If you install sqlite-net via Nuget you got two classes SQLite.cs and SQLiteAsync.cs for asynchronous database access. In the class SQLite.cs you will find the property attributes for your data classes. If you want to put them in a reusable library, you have to comment the necessary attribute definitions and copy them to your data classes library. Really dirty – but it works .-)
So in my portable library I have also a SQLite.cs file with only the primary attribute definition (I need no more) in the SQLite namespace:
The whole demo project you could find on my SkyDrive: http://sdrv.ms/RFOrNQ