Class Realm.Dynamic
A class that exposes the dynamic API for a Realm instance.
Namespace: Realms
Assembly: Realm.dll
Syntax
[Preserve(AllMembers = true)]
public class Dynamic
Methods
| Improve this Doc View SourceAddEmbeddedObjectToList(IRealmCollection<EmbeddedObject>)
Creates an embedded object and adds it to the specified list. This also assigns correct ownership of the newly created embedded object.
Declaration
public dynamic AddEmbeddedObjectToList(IRealmCollection<EmbeddedObject> list)
Parameters
Type | Name | Description |
---|---|---|
IRealmCollection<EmbeddedObject> | list | The list to which the object will be added. |
Returns
Type | Description |
---|---|
Object | 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(IRealmCollection<EmbeddedObject>), InsertEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32), and SetEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32) have to be used instead of Add(T), Insert(Int32, T), and Item[Int32].
See Also
All(String)
Get a view of all the objects of a particular type.
Declaration
public IQueryable<dynamic> All(string className)
Parameters
Type | Name | Description |
---|---|---|
String | className | The type of the objects as defined in the schema. |
Returns
Type | Description |
---|---|
IQueryable<Object> | 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(RealmObjectBase, 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 dynamic CreateEmbeddedObjectForProperty(RealmObjectBase parent, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
RealmObjectBase | parent | The parent RealmObject or EmbeddedObject 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 |
---|---|
Object | A dynamically-accessed embedded object. |
CreateObject(String, Object)
Factory for a managed object in a realm. Only valid within a write Transaction.
Declaration
public dynamic CreateObject(string className, object primaryKey)
Parameters
Type | Name | Description |
---|---|---|
String | className | The type of object to create as defined in the schema. |
Object | primaryKey | The primary key of object to be created. If the object doesn't have primary key defined, this argument is ignored. |
Returns
Type | Description |
---|---|
Object | 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. |
ArgumentNullException | If you pass |
ArgumentException | If you pass |
Find(String, Nullable<ObjectId>)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public dynamic Find(string className, ObjectId? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
String | className | Name of class in dynamic situation. |
Nullable<MongoDB.Bson.ObjectId> | primaryKey | Primary key to be matched exactly, same as an == search. |
Returns
Type | Description |
---|---|
Object |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the RealmObject class T lacks PrimaryKeyAttribute. |
Find(String, Nullable<Guid>)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public dynamic Find(string className, Guid? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
String | className | Name of class in dynamic situation. |
Nullable<Guid> | primaryKey | Primary key to be matched exactly, same as an == search. |
Returns
Type | Description |
---|---|
Object |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the RealmObject class T lacks PrimaryKeyAttribute. |
Find(String, Nullable<Int64>)
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
Declaration
public dynamic Find(string className, long? primaryKey)
Parameters
Type | Name | Description |
---|---|---|
String | className | Name of class in dynamic situation. |
Nullable<Int64> | primaryKey | Primary key to be matched exactly, same as an == search.
An argument of type |
Returns
Type | Description |
---|---|
Object |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the RealmObject 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 dynamic 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 |
---|---|
Object |
|
Exceptions
Type | Condition |
---|---|
RealmClassLacksPrimaryKeyException | If the RealmObject class T lacks PrimaryKeyAttribute. |
InsertEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32)
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 dynamic InsertEmbeddedObjectInList(IRealmCollection<EmbeddedObject> list, int index)
Parameters
Type | Name | Description |
---|---|---|
IRealmCollection<EmbeddedObject> | list | The list in which the object will be inserted. |
Int32 | index | The index at which the object will be inserted. |
Returns
Type | Description |
---|---|
Object | 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(IRealmCollection<EmbeddedObject>), InsertEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32), and SetEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32) have to be used instead of Add(T), Insert(Int32, T), and Item[Int32].
See Also
RemoveAll(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 |
SetEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32)
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 dynamic SetEmbeddedObjectInList(IRealmCollection<EmbeddedObject> list, int index)
Parameters
Type | Name | Description |
---|---|---|
IRealmCollection<EmbeddedObject> | list | The list in which the object will be set. |
Int32 | index | The index at which the object will be set. |
Returns
Type | Description |
---|---|
Object | 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(IRealmCollection<EmbeddedObject>), InsertEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32), and SetEmbeddedObjectInList(IRealmCollection<EmbeddedObject>, Int32) have to be used instead of Add(T), Insert(Int32, T), and Item[Int32].
Setting an object at an index will remove the existing object from the list and unown it. Since unowned embedded objects are automatically deleted,
the old object that the list contained at index
will get deleted when the transaction is committed.