Consider the simple model:
public class Session : RealmObject
{
[ObjectId]
public string UserId { get; set; }
public string Token { get; set; }
}
How to get the Session
instance by ID or null
if it doesn't exist?
var realm = Realm.GetInstance ();
var q = realm.All<Session> ().Where ((x) => x.UserId = "1");
// This won't work if no session is saved:
// var session = q.First ();
// and this won't either
// var session = q.FirstOrDefault ();
// And this is mmm... kind of strange but it's working :)
var session = q.Count() > 0 ? q.First() : null;
So, how it's supposed to be done by design?