Realm is a mobile database that runs directly on phones, tablets or wearables. It supports all major mobile and desktop operating systems, such as iOS, Android, UWP, macOS, Linux, and Windows. For a full list of supported platforms and their versions, check out the Platform and Framework Compatibility section in the documentation.
- Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets, and wearables.
- Simple: Data is directly exposed as objects and queryable by code, removing the need for ORM's riddled with performance & maintenance issues. Plus, we've worked hard to keep our API down to just a few common classes: most of our users pick it up intuitively, getting simple apps up & running in minutes.
- Modern: Realm supports relationships, generics, vectorization and modern C# idioms.
- Fast: Realm is faster than even raw SQLite on common operations while maintaining an extremely rich feature set.
- Device Sync: Makes it simple to keep data in sync across users, devices, and your backend in real-time. Get started for free with a template application and create the cloud backend.
Define a persistable model by inheriting from IRealmObject
. The Realm source generator will generate an implementation for most of the functionality, so you only need to specify the properties you want to persist:
public partial class Person : IRealmObject
{
[PrimaryKey]
public ObjectId Id { get; private set; } = ObjectId.GenerateNewId();
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTimeOffset Birthday { get; set; }
// You can define constructors as usual
public Person(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
Open a Realm instance by calling Realm.GetInstance
:
// You can provide a relative or an absolute path to the Realm file or let
// Realm use the default one.
var realm = Realm.GetInstance("people.realm");
Add, read, update, and remove objects by calling the corresponding API on the Realm
instance:
// Always mutate the Realm instance in a write transaction
realm.Write(() =>
{
realm.Add(new Person("John", "Smith"));
});
var peopleWithJ = realm.All<Person>().Where(p => p.FirstName.StartsWith("J"));
// All Realm collections and objects are reactive and implement INotifyCollectionChanged/INotifyPropertyChanged
peopleWithJ.AsRealmCollection().CollectionChanged += (s, e) =>
{
// React to notifications
};
For more examples, see the detailed instructions in our User Guide to add Realm to your solution.
The documentation can be found at mongodb.com/docs/atlas/device-sdks/sdk/dotnet/. The API reference is located at mongodb.com/docs/realm-sdks/dotnet/latest/.
- Need help with your code?: Look for previous questions on the #realm tag — or ask a new question. You can also check out our Community Forum where general questions about how to do something can be discussed.
- Have a bug to report? Open an issue. If possible, include the version of Realm, a full log, the Realm file, and a project that shows the issue.
- Have a feature request? Open an issue. Tell us what the feature should do, and why you want the feature.