Data access in monotouch (C# for iphone) is a royal pain in the ass. I know most developers, whether C# or objc, are just stuffing SQL statements directly into their code but is one of my pet hates. Consequently I’ve been looking for a way around it.
As it turns out there’s no nice solution but there’s a half way solution that sucks a bit less.
It’s all Apple’s fault
The iPhone ships with sqlite (good) but it is unfortunately sqlite v3.0 (bad) which lacks the ability to expose schema information (v. bad). Consequently, schema querying which most ORM’s rely on doesn’t work.
Things that don’t work
At this point I really wanted to put my foot thru my iMac’s screen and snap my iPhone in half. No, really.
Salvation
One I came across early but dismissed was sqlite-net. It’s a very thin wrapper over sqlite, provides basic class mapping but still requires SQL to be embedded in your app. It provides no assistance performing updates. The upside is it handles the task of transferring results into your DTO’s and auto-updating primary keys post insert.
It’s not ideal but it’s still a better than nothing. Personally I really hope Novell address the issues holding back catnap-orm because it is awesome.
I hope this post saves some poor developer their sanity.