Define a Realm Object Schema - .NET SDK¶
An object schema is a configuration object that defines the properties and relationships of a Realm object. Realm client applications define object schemas with the native class implementation in their respective language using the Realm Object Model.
Object schemas specify constraints on object properties such as the data type of each property and whether or not a property is required. Schemas can also define relationships between object types in a realm.
Every Realm app has a Realm Schema composed of a list of object schemas for each type of object that the realms in that application may contain. MongoDB Realm guarantees that all objects in a realm conform to the schema for their object type and validates objects whenever they're created, modified, or deleted.
Define a Relationship Property¶
Realm Database supports several kinds of object relationships.
Many-to-One¶
To set up a many-to-one or one-to-one relationship, create a property in your application
whose type inherits RealmObject
or EmbeddedObject
:
public class Dog : RealmObject { // ... other property declarations public Person Owner { get; set; } } public class Person : RealmObject { // ... other property declarations public string Name { get; set; } }
Each Dog
references zero or one Person
instances. Nothing prevents
multiple Dog
instances from referencing the same Person
as an owner;
the distinction between a many-to-one and a one-to-one relationship is
up to your application.
Setting a relationship property to null removes the connection between objects, but Realm Database does not delete the referenced object unless that object is embedded.
Many-to-Many¶
You can create a relationship between one object and any number of objects
using a property of type IList<T>