Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Cross platform SQLite ORM

$
0
0

Greetings,

I'm creating a cross-platform (iOS, Android and WP8) Application and I want to include database persistence. I've used MvvmCross SQLite.Net plugin for other simple projects and I'm quite happy with it. I tried to use it for this new project but got stuck with a SQLite.Net limitation: it only supports 1:1 relationships, so no 1:N or N:M relationships are supported out-of-the-box.

I've seen a pull request that includes 1:N relationships, but it's not even in the master branch and only solves part of the problem.

I've checked the MWC example to see how they handle relationships, that create intermediate classes for N:M relationships and fetch the relationships when you get the object. For example:

    public static Speaker GetSpeaker(int id)
        {
            lock (locker) {
                Speaker speaker = (from s in me.Table ()
                        where s.ID == id
                        select s).FirstOrDefault ();

                var keys = (from ss in me.Table ()
                                    where ss.SpeakerKey == speaker.Key
                                    select ss).ToList();
                // HACK: gets around "Default constructor not found for type System.String" error
                speaker.SessionKeys = keys.Select (x => x.SpeakerKey).ToList ();

                var sessions = GetItems();

                var sessionsForSpeaker = (from se in sessions
                                where speaker.SessionKeys.Contains (se.Key)
                                select se).ToList ();

                speaker.Sessions = sessionsForSpeaker;

                return speaker;
            }
        }

Writing the N:M wiring classes and all the boilerplate code for manually handling the relationships sends chills down my spine, so I started evaluating other ORM alternatives for SQLite.

Initially Vici Coolstorage seemed like a good alternative: support for MonoTouch, MonoDroid and WP; 1:1, 1:N and N:M relationships, lazy fetch and automatic pre-fetching, etc.

But when the integration started (I wanted to create a MvvmCross plugin for easier reuse) I saw that it has a nasty dependency on Vici Core. It seems like an overkill dependency for a simple SQLite ORM.

I read someone recommending Catnap as a good alternative for SQLite.Net, it seems to be decently documented and quite simple integration. But 7 months of inactivity and some dead branches makes me wonder if the projects has been abandoned.

I don't think that I'm the first one having this issue, so could you please share your experiences and recommendations about this concern?

Thank you for your time, Guillermo


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>