Struct Realm.Dynamic
A class that exposes the dynamic API for a Realm instance.
Inherited Members
Namespace: Realms
Assembly: Realm.dll
Syntax
[Preserve(AllMembers = true)]
public readonly struct Realm.Dynamic
Methods
| Edit this page View SourceAddEmbeddedObjectToDictionary(object, string)
Creates an embedded object and adds it to the specified dictionary. This also assigns correct ownership of the newly created embedded object.
Declaration
public IEmbeddedObject AddEmbeddedObjectToDictionary(object dictionary, string key)
Parameters
Type | Name | Description |
---|---|---|
object | dictionary | The dictionary to which the object will be added. |
string | key | The key for which the object will be added. |
Returns
Type | Description |
---|---|
IEmbeddedObject | The newly created object, after it has been added to the dictionary. |
Remarks
Dictionaries containing embedded objects cannot directly add objects as that would require constructing an unowned embedded object, which is not possible. This is why AddEmbeddedObjectToDictionary(object, string) and SetEmbeddedObjectInDictionary(object, string) have to be used instead of Add(TKey, TValue) and this[TKey].
See Also
| Edit this page View SourceAddEmbeddedObjectToList(object)
Creates an embedded object and adds it to the specified list. This also assigns correct ownership of the newly created embedded object.
Declaration
public IEmbeddedObject AddEmbeddedObjectToList(object list)
Parameters
Type | Name | Description |
---|---|---|
object | list | The list to which the object will be added. |
Returns
Type | Description |
---|---|
IEmbeddedObject | The newly created object, after it has been added to the back of the list. |
Remarks
Lists of embedded objects cannot directly add objects as that would require constructing an unowned embedded object, which is not possible. This is why AddEmbeddedObjectToList(object), InsertEmbeddedObjectInList(object, int), and SetEmbeddedObjectInList(object, int) have to be used instead of Add(T), Insert(int, T), and this[int].
See Also
| Edit this page View SourceAll(string)
Get a view of all the objects of a particular type.
Declaration
public IQueryable<IRealmObject> All(string className)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of the objects as defined in the schema. |
Returns
Type | Description |
---|---|
IQueryable<IRealmObject> | A queryable collection that without further filtering, allows iterating all objects of className, in this realm. |
Remarks
Because the objects inside the view are accessed dynamically, the view cannot be queried into using LINQ or other expression predicates.
CreateEmbeddedObjectForProperty(IRealmObjectBase, string)
Factory for a managed embedded object in a realm. Only valid within a write Transaction. Embedded objects need to be owned immediately which is why they can only be created for a specific property.
Declaration
public IEmbeddedObject CreateEmbeddedObjectForProperty(IRealmObjectBase parent, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
IRealmObjectBase | parent | The parent IRealmObject or IEmbeddedObject that will own the newly created embedded object. |
string | propertyName | The property to which the newly created embedded object will be assigned. |
Returns
Type | Description |
---|---|
IEmbeddedObject | A dynamically-accessed embedded object. |
CreateObject(string)
Factory for a managed object without a primary key in a realm. Only valid within a write Transaction.
Declaration
public IRealmObjectBase CreateObject(string className)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of object to create as defined in the schema. |
Returns
Type | Description |
---|---|
IRealmObjectBase | A dynamically-accessed Realm object. |
Remarks
If the realm instance has been created from an un-typed schema (such as when migrating from an older version of a realm) the returned object will be purely dynamic. If the realm has been created from a typed schema as is the default case when calling GetInstance(RealmConfigurationBase?) the returned object will be an instance of a user-defined class.
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If you use this method on an object that has primary key defined. |
CreateObject(string, ObjectId?)
Factory for a managed object with a primary key in a realm. Only valid within a write Transaction.
Declaration
public IRealmObjectBase CreateObject(string className, ObjectId? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of object to create as defined in the schema. |
ObjectId? | primaryKey | The primary key of the object to create. |
Returns
Type | Description |
---|---|
IRealmObjectBase | A dynamically-accessed Realm object. |
Remarks
If the realm instance has been created from an un-typed schema (such as when migrating from an older version of a realm) the returned object will be purely dynamic. If the realm has been created from a typed schema as is the default case when calling GetInstance(RealmConfigurationBase?) the returned object will be an instance of a user-defined class.
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If the type of the |
CreateObject(string, Guid?)
Factory for a managed object with a primary key in a realm. Only valid within a write Transaction.
Declaration
public IRealmObjectBase CreateObject(string className, Guid? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of object to create as defined in the schema. |
Guid? | primaryKey | The primary key of the object to create. |
Returns
Type | Description |
---|---|
IRealmObjectBase | A dynamically-accessed Realm object. |
Remarks
If the realm instance has been created from an un-typed schema (such as when migrating from an older version of a realm) the returned object will be purely dynamic. If the realm has been created from a typed schema as is the default case when calling GetInstance(RealmConfigurationBase?) the returned object will be an instance of a user-defined class.
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If the type of the |
CreateObject(string, long?)
Factory for a managed object with a primary key in a realm. Only valid within a write Transaction.
Declaration
public IRealmObjectBase CreateObject(string className, long? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of object to create as defined in the schema. |
long? | primaryKey | The primary key of the object to create. |
Returns
Type | Description |
---|---|
IRealmObjectBase | A dynamically-accessed Realm object. |
Remarks
If the realm instance has been created from an un-typed schema (such as when migrating from an older version of a realm) the returned object will be purely dynamic. If the realm has been created from a typed schema as is the default case when calling GetInstance(RealmConfigurationBase?) the returned object will be an instance of a user-defined class.
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If the type of the |
CreateObject(string, string?)
Factory for a managed object with a primary key in a realm. Only valid within a write Transaction.
Declaration
public IRealmObjectBase CreateObject(string className, string? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | The type of object to create as defined in the schema. |
string | primaryKey | The primary key of the object to create. |
Returns
Type | Description |
---|---|
IRealmObjectBase | A dynamically-accessed Realm object. |
Remarks
If the realm instance has been created from an un-typed schema (such as when migrating from an older version of a realm) the returned object will be purely dynamic. If the realm has been created from a typed schema as is the default case when calling GetInstance(RealmConfigurationBase?) the returned object will be an instance of a user-defined class.
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If the type of the |
Find(string, ObjectId?)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public IRealmObject? Find(string className, ObjectId? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | Name of class in dynamic situation. |
ObjectId? | primaryKey | Primary key to be matched exactly, same as an == search. |
Returns
Type | Description |
---|---|
IRealmObject |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the IRealmObject class T lacks PrimaryKeyAttribute. |
Find(string, Guid?)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public IRealmObject? Find(string className, Guid? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | Name of class in dynamic situation. |
Guid? | primaryKey | Primary key to be matched exactly, same as an == search. |
Returns
Type | Description |
---|---|
IRealmObject |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the IRealmObject class T lacks PrimaryKeyAttribute. |
Find(string, long?)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public IRealmObject? Find(string className, long? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | Name of class in dynamic situation. |
long? | primaryKey | Primary key to be matched exactly, same as an == search.
An argument of type |
Returns
Type | Description |
---|---|
IRealmObject |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the IRealmObject class T lacks PrimaryKeyAttribute. |
Find(string, string?)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public IRealmObject? Find(string className, string? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
string | className | Name of class in dynamic situation. |
string | primaryKey | Primary key to be matched exactly, same as an == search. |
Returns
Type | Description |
---|---|
IRealmObject |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the IRealmObject class T lacks PrimaryKeyAttribute. |
InsertEmbeddedObjectInList(object, int)
Creates an embedded object and inserts it in the specified list at the specified index. This also assigns correct ownership of the newly created embedded object.
Declaration
public IEmbeddedObject InsertEmbeddedObjectInList(object list, int index)
Parameters
Type | Name | Description |
---|---|---|
object | list | The list in which the object will be inserted. |
int | index | The index at which the object will be inserted. |
Returns
Type | Description |
---|---|
IEmbeddedObject | The newly created object, after it has been inserted in the list. |
Remarks
Lists of embedded objects cannot directly add objects as that would require constructing an unowned embedded object, which is not possible. This is why AddEmbeddedObjectToList(object), InsertEmbeddedObjectInList(object, int), and SetEmbeddedObjectInList(object, int) have to be used instead of Add(T), Insert(int, T), and this[int].
See Also
| Edit this page View SourceRemoveAll(string)
Remove all objects of a type from the Realm.
Declaration
public void RemoveAll(string className)
Parameters
Type | Name | Description |
---|---|---|
string | className | Type of the objects to remove as defined in the schema. |
Exceptions
Type | Condition |
---|---|
RealmInvalidTransactionException | If you invoke this when there is no write Transaction active on the Realm. |
ArgumentException | If you pass |
SetEmbeddedObjectInDictionary(object, string)
Creates an embedded object and sets it in the specified dictionary for the specified key. This also assigns correct ownership of the newly created embedded object.
Declaration
public IEmbeddedObject SetEmbeddedObjectInDictionary(object dictionary, string key)
Parameters
Type | Name | Description |
---|---|---|
object | dictionary | The dictionary in which the object will be set. |
string | key | The key for which the object will be set. |
Returns
Type | Description |
---|---|
IEmbeddedObject | The newly created object, after it has been assigned to the specified key in the dictionary. |
Remarks
Dictionaries containing embedded objects cannot directly add objects as that would require constructing an unowned embedded object, which is not possible. This is why AddEmbeddedObjectToDictionary(object, string) and SetEmbeddedObjectInDictionary(object, string) have to be used instead of Add(TKey, TValue) and this[TKey].
See Also
| Edit this page View SourceSetEmbeddedObjectInList(object, int)
Creates an embedded object and sets it in the specified list at the specified index. This also assigns correct ownership of the newly created embedded object.
Declaration
public IEmbeddedObject SetEmbeddedObjectInList(object list, int index)
Parameters
Type | Name | Description |
---|---|---|
object | list | The list in which the object will be set. |
int | index | The index at which the object will be set. |
Returns
Type | Description |
---|---|
IEmbeddedObject | The newly created object, after it has been set to the specified index in the list. |
Remarks
Lists of embedded objects cannot directly add objects as that would require constructing an unowned embedded object, which is not possible. This is why AddEmbeddedObjectToList(object), InsertEmbeddedObjectInList(object, int), and SetEmbeddedObjectInList(object, int) have to be used instead of Add(T), Insert(int, T), and this[int].
Setting an object at an index will remove the existing object from the list and un-own it. Since unowned embedded objects are automatically deleted, the old object that the list contained atindex
will get deleted when the transaction is committed.