Realm Xamarin  v0.77.2
Realm for Xamarin
Realm for Xamarin

The C# API of Realm is incredibly simple because it leverages the power of LINQ for querying and the Fody weaver to transform plain C# class declarations into persistent objects.

The main classes you will use are:

Helper classes you may use are:

Querying and Sorting are provided on a Realm using standard LINQ syntax including Where and OrderBy.

UnderstandingRealmForXamarin.png
Realm Overview Diagram

Documentation

The documentation can be found at realm.io/docs/dotnet/latest.

The API reference is located at realm.io/docs/dotnet/latest/api.

Source

Source is available on github.

Instructions on how to build from source are included in that repository's README.md.

Minimal Sample

This trivial sample shows the use of most of the classes mentioned above:

Note that in most debugging situations the default Realm will be retained so if you run this sample fragment multiple times you should see the number created increase. This is on purpose so you are assured the database is being persisted between runs.

1 using Realms;
2 
3 class Hero : RealmObject
4 {
5  public string SuperName { get; set; }
6  public int SuperScore { get; set; }
7 }
8 
9 /// put this code in an OnLoad or simple button-press handler
10 
11  var _realm = Realm.GetInstance();
12  using (var trans = _realm.BeginWrite())
13  {
14  var hero = _realm.CreateObject<Hero>();
15  hero.SuperName = "Thor";
16  hero.SuperScore = 100;
17  trans.Commit();
18  }
19  var numAwe = _realm.All<Hero>().Count();
20  System.Diagnostics.Debug.WriteLine($"Created {numAwe} heroes");
21  _realm.Close();

Problem reports and Feature requests

The github issue tracker can be used to report problems or make feature requests.