Realm 11.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Realm --version 11.1.0
NuGet\Install-Package Realm -Version 11.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Realm" Version="11.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Realm --version 11.1.0
#r "nuget: Realm, 11.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Realm as a Cake Addin
#addin nuget:?package=Realm&version=11.1.0

// Install Realm as a Cake Tool
#tool nuget:?package=Realm&version=11.1.0

Realm

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 Supported Platforms sub-section in the documentation.

Features

  • 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.

Getting Started

Model definition

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 file

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");

CRUD operations

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.

Documentation

The documentation can be found at docs.mongodb.com/realm/dotnet/. The API reference is located at docs.mongodb.com/realm-sdks/dotnet/latest/.

Getting Help

  • 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.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid is compatible. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios is compatible. 
Xamarin.Mac xamarinmac is compatible. 
Xamarin.TVOS xamarintvos is compatible. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (39)

Showing the top 5 NuGet packages that depend on Realm:

Package Downloads
ppy.osu.Game

Package Description

Iridium360.Connect.Framework

This framework allows you to bind your Android or iOS device with i360RockSTAR tracker

ItEnterprise.Common.CoreStandard

ItEnterprise Common.CoreStandard for Xamarin Forms

Arc4u.Standard.Diagnostics.Serilog.Sinks.RealmDb

Arc4u Diagnostics Serilog Sink to RealmDB

ItEnterprise.WmsStandard

ItEnterprise WmsStandard for Xamarin Forms

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on Realm:

Repository Stars
ppy/osu
rhythm is just a *click* away!
realm/realm-dotnet
Realm is a mobile database: a replacement for SQLite & ORMs
sgermosen/xReader
XML, NEWS, RSS & Scrapping Reader maked in Xamarin, for educational purpose.
realm/realm-draw
The official Realm Draw app used in promotional videos
dsa28s/windows-hangul-clock
Hangul Clock for Windows Desktop Widget
Version Downloads Last updated
12.0.0 2,948 4/17/2024
11.7.0 51,738 2/5/2024
11.6.1 60,834 11/17/2023
11.6.0 12,514 11/4/2023
11.5.0 165,994 9/16/2023
11.4.0 24,175 8/16/2023
11.3.0 32,163 7/26/2023
11.2.0 14,892 7/8/2023
11.1.2 97,002 6/20/2023
11.1.1 5,771 6/19/2023
11.1.0 2,609 6/17/2023
11.0.0 36,946 5/8/2023
10.21.1 33,193 4/21/2023
10.21.0 22,376 3/24/2023
10.20.0 86,330 2/10/2023
10.19.0 32,371 1/6/2023
10.18.0 124,582 11/2/2022
10.17.0 85,829 10/6/2022
10.16.0 12,608 10/3/2022
10.15.1 104,349 8/8/2022
10.15.0 5,526 8/5/2022
10.14.0 171,875 6/2/2022
10.13.0 26,929 5/18/2022
10.12.0 18,076 5/5/2022
10.11.2 34,675 4/21/2022
10.11.1 20,642 3/31/2022
10.11.0 5,414 3/28/2022
10.10.0 94,568 2/28/2022
10.9.0 73,508 1/21/2022
10.8.0 37,669 1/17/2022
10.7.1 101,806 11/20/2021
10.7.0 7,111 11/10/2021
10.6.0 158,060 9/30/2021
10.5.1 17,996 9/22/2021
10.5.0 30,526 9/9/2021
10.4.1 3,681 9/3/2021
10.4.0 11,259 8/31/2021
10.3.0 137,306 7/7/2021
10.2.1 26,676 7/1/2021
10.2.0 26,539 6/15/2021
10.2.0-beta.2 761 5/5/2021
10.2.0-beta.1 350 4/12/2021
10.1.4 19,059 5/12/2021
10.1.3 20,307 4/29/2021
10.1.2 29,374 3/19/2021
10.1.1 22,096 2/25/2021
10.1.0 13,150 2/9/2021
10.0.1 6,834 2/2/2021
10.0.0-beta.6 430 1/26/2021
10.0.0-beta.5 636 1/19/2021
10.0.0-beta.3 1,151 12/10/2020
10.0.0-beta.2 1,464 11/4/2020
10.0.0-beta.1 727 10/16/2020
10.0.0-alpha.43 360 10/9/2020
10.0.0-alpha.34 470 10/4/2020
5.1.3 24,878 2/10/2021
5.1.2 83,574 10/20/2020
5.1.1 27,551 10/2/2020
5.1.0 6,622 9/30/2020
5.0.1 10,720 9/9/2020
4.3.0 270,694 2/5/2020
4.2.0 69,667 10/8/2019
4.1.0 86,398 8/6/2019
4.0.1 20,018 6/27/2019
4.0.0 6,256 6/14/2019
3.4.0 101,140 1/9/2019
3.3.0 26,280 11/8/2018
3.2.1 44,008 9/27/2018
3.2.0 15,192 9/4/2018
3.1.0 32,505 7/4/2018
3.0.0 108,373 4/16/2018
2.2.0 12,699 3/22/2018
2.1.0 54,577 11/13/2017
2.0.0 18,271 10/17/2017
2.0.0-rc1 2,572 10/3/2017
1.6.0 35,392 8/15/2017
1.5.0 17,975 6/20/2017
1.4.0 14,880 5/19/2017
1.3.0 3,722 5/16/2017
1.2.1 7,937 5/1/2017
1.2.0 5,946 4/4/2017
1.1.1 7,497 3/15/2017
1.1.0 3,650 3/3/2017
1.0.4 4,880 2/21/2017
1.0.3 17,054 2/14/2017
0.82.1 18,468 1/27/2017
0.82.0 3,338 1/23/2017
0.81.0 5,428 12/15/2016
0.80.0 11,534 10/27/2016
0.78.1 20,583 9/15/2016
0.78.0 2,744 9/11/2016
0.77.2 5,616 8/11/2016
0.77.1 3,176 7/28/2016
0.76.1 6,070 6/15/2016
0.76.0 3,386 6/9/2016
0.75.0 3,216 6/3/2016
0.74.1 5,789 5/10/2016

## 11.1.0 (2023-06-17)

### Enhancements
* Deprecate the `Realm.SourceGenerator` and `Realm.Fody` packages. The source generation and weaver assemblies are now contained in the main `Realm` package. This should be a transparent change for users who only referenced the `Realm` package, but if you explicitly added a package reference to `Realm.SourceGenerator` or `Realm.Fody`, you should remove it. (PR [#3319](https://github.com/realm/realm-dotnet/pull/3319))
* Automatically handle `RealmObject`->`EmbeddedObject` migrations by duplicating objects referenced by multiple parents as well as removing "orphaned" objects. (Issue [#2408](https://github.com/realm/realm-dotnet/issues/2408))
* New notifiers can now be registered in write transactions until changes have actually been made in the write transaction. This makes it so that new notifications can be registered inside change notifications triggered by beginning a write transaction (unless a previous callback performed writes). (Core 13.10.1)
* Partition-Based to Flexible Sync Migration for migrating a client app that uses partition based sync to use flexible sync under the hood if the server has been migrated to flexible sync is officially supported with this release. Any clients using an older version of Realm (including the original support released in Core 11.0.0) will receive a "switch to flexible sync" error message when trying to sync with the app. (Core 13.11.0)
* Support sort/distinct based on values from a dictionary e.g. `.Filter("TRUEPREDICATE SORT(meta['age'])")`. (Core 13.14.0)
* Added initial support for geospatial queries on points. (Issue [#3299](https://github.com/realm/realm-dotnet/issues/3299))
 * In this version, only queries of the form "is this point contained in this shape" (equivalent to [$geoWithin](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/) in MongoDB) are supported.
 * There is no index support right now.
 * There is no dedicated type for persisted geospatial points. Instead, points should be stored as GeoJson-shaped embedded object and queries will use duck-typing to check if the shape contains the object. For convenience, here's an example embedded object that you can use in lieu of a Realm-provided dedicated type:
   ```csharp
   public partial class Location : IEmbeddedObject
   {
     // The coordinates and type properties are mandatory but may be private.
     // You can add more fields if necessary - those will be ignored when doing
     // geospatial queries.
     [MapTo("coordinates")]
     private IList<double> Coordinates { get; } = null!;

     [MapTo("type")]
     private string Type { get; set; } = "Point";

     public double Latitude => Coordinates.Count > 1 ? Coordinates[1] : throw new Exception($"Invalid coordinate array. Expected at least 2 elements, but got: {Coordinates.Count}");

     public double Longitude => Coordinates.Count > 1 ? Coordinates[0] : throw new Exception($"Invalid coordinate array. Expected at least 2 elements, but got: {Coordinates.Count}");

     public Location(double latitude, double longitude)
     {
       // According to the GeoJson spec, longitude must come first in the
       // coordinates array.
       Coordinates.Add(longitude);
       Coordinates.Add(latitude);
     }
   }

   // Example usage
   public partial class Company : IRealmObject
   {
     public Location Location { get; set; }
   }
   ```
 * Three new shape types and one helper point type are added to allow you to check for containment:
   * `GeoPoint`: a building block for the other shape types - it cannot be used as a property type on your models and is only intended to construct the other shape types. It can be constructed implicitly from a value tuple of latitude and longitude:
     ```csharp
     var point = new GeoPoint(latitude: 12.345, longitude: 67.890);
     var point = (12.345, 67.890);
     ```
   * `GeoCircle`: a shape representing a circle on a sphere constructed from a center and radius:
     ```csharp
     var circle = new GeoCircle(center: (12.34, 56.78), radius: 10); // radius in radians
     var circle = new GeoCircle((12.34, 56.78), Distance.FromKilometers(10));
     ```
   * `GeoBox`: a shape representing a box on a sphere constructed from its bottom left and top right corners:
     ```csharp
     var box = new GeoBox((12.34, 56.78), (15.34, 59.78));
     ```
   * `GeoPolygon`: an arbitrary polygon constructed from an outer ring and optional holes:
     ```csharp
     var polygon = new GeoPolygon((10, 10), (20, 20), (0, 20), (10, 10)); // a triangle with no holes

     var outerRing = new GeoPoint[] { (10, 10), (20, 20), (0, 20), (10, 10) };
     var hole1 = new GeoPoint[] { (1, 1), (2, 2), (0, 2), (1, 1) };
     var hole2 = new GeoPoint[] { (5, 5), (6, 6), (4, 6), (5, 5) };

     var polygon = new GeoPolygon(outerRing, hole1, hole2); // A triangle with two smaller triangular holes
     ```
 * Querying can be done either via LINQ or RQL:
   ```csharp
   var matches = realm.All<Company>().Where(c => QueryMethods.GeoWithin(c.Location, circle));
   var matches = realm.All<Company>().Filter("Location GEOWITHIN $0", circle);
   ```
* Support sort/distinct based on values from a dictionary e.g. `realm.All<MyModel>().Filter("TRUEPREDICATE SORT(meta['age'])")`. (Core 13.14.0)
* Fixed a potential crash when opening the realm after failing to download a fresh FLX realm during an automatic client reset. (Core 13.14.0)

### Fixed
* Fixed a fatal error (reported to the sync error handler) during client reset (or automatic PBS to FLX migration) if the reset has been triggered during an async open and the schema being applied has added new classes. (Core 13.11.0)
* Full text search would sometimes find words where the word only matches the beginning of the search token. (Core 13.11.0)
* We could crash when removing backlinks in cases where forward links did not have a corresponding backlink due to corruption. We now silently ignore this inconsistency in release builds, allowing the app to continue. (Core 13.12.0)
* `IDictionary<string, IRealmObject?>` would expose unresolved links rather than mapping them to null. In addition to allowing invalid objects to be read from Dictionaries, this resulted in queries on Dictionaries sometimes having incorrect results. (Core 13.12.0)
* Access token refresh for websockets was not updating the location metadata. (Core 13.13.0)
* Using both synchronous and asynchronous transactions on the same thread or scheduler could hit the assertion failure "!realm.is_in_transaction()" if one of the callbacks for an asynchronous transaction happened to be scheduled during a synchronous transaction. (Core 13.13.0)
* Fixed a potential crash when opening the realm after failing to download a fresh FLX realm during an automatic client reset. (Core 13.14.0)
* Setting a property containing an embedded object to the same embedded object used to throw an exception with the text `Can't link to an embedded object that is already managed`. Now it is a no-op instead. (Issue [#3262](https://github.com/realm/realm-dotnet/issues/3262))

### Compatibility
* Realm Studio: 13.0.0 or later.

### Internal
* Using Core 13.15.0.
* Overhauled and extended the metrics collection of the SDK to better drive future development effort. (PR [#3209](https://github.com/realm/realm-dotnet/pull/3209))