Realm Xamarin
v0.78.0
Realm for Xamarin
|
A Realm instance (also referred to as a realm) represents a Realm database. More...
Inherits IDisposable.
Public Member Functions | |
RealmResults< dynamic > | All (string className) |
Get a view of all the objects of a particular type More... | |
RealmResults< T > | All< T > () |
Extract an iterable set of objects for direct use or further query. More... | |
Transaction | BeginWrite () |
Factory for a write Transaction. Essential object to create scope for updates. More... | |
void | Close () |
Closes the Realm if not already closed. Safe to call repeatedly. Note that this will close the file. Other references to the same database on the same thread will be invalidated. More... | |
dynamic | CreateObject (string className) |
Factory for a managed object in a realm. Only valid within a Write transaction. More... | |
T | CreateObject< T > () |
Factory for a managed object in a realm. Only valid within a Write transaction. More... | |
void | Dispose () |
Dispose automatically closes the Realm if not already closed. More... | |
override bool | Equals (Object rhs) |
Generic override determines whether the specified System.Object is equal to the current Realm. More... | |
bool | Equals (Realm rhs) |
Determines whether the specified Realm is equal to the current Realm. More... | |
override int | GetHashCode () |
Serves as a hash function for a Realm based on the core instance. More... | |
bool | IsSameInstance (Realm rhs) |
Determines whether this instance is the same core instance as the specified rhs. More... | |
void | Manage< T > (T obj) |
This realm will start managing a RealmObject which has been created as a standalone object. More... | |
RealmObject | ObjectForPrimaryKey (string className, Int64 id) |
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property. More... | |
RealmObject | ObjectForPrimaryKey (string className, string id) |
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property. More... | |
T | ObjectForPrimaryKey< T > (Int64 id) |
Fast lookup of an object from a class which has a PrimaryKey property. More... | |
T | ObjectForPrimaryKey< T > (string id) |
Fast lookup of an object from a class which has a PrimaryKey property. More... | |
delegate void | RealmChangedEventHandler (object sender, EventArgs e) |
Handler type used by RealmChanged More... | |
bool | Refresh () |
Update a Realm and outstanding objects to point to the most recent data for this Realm. This is only necessary when you have a Realm on a non-runloop thread that needs manual refreshing. More... | |
void | Remove (RealmObject obj) |
Removes a persistent object from this realm, effectively deleting it. More... | |
void | RemoveAll (string className) |
Remove all objects of a type from the realm. More... | |
void | RemoveAll () |
Remove all objects of all types managed by this realm. More... | |
void | RemoveAll< T > () |
Remove all objects of a type from the realm. More... | |
void | RemoveRange< T > (RealmResults< T > range) |
Remove objects matcing a query from the realm. More... | |
void | Write (Action action) |
Execute an action inside a temporary transaction. If no exception is thrown, the transaction will automatically be committed. More... | |
Task | WriteAsync (Action< Realm > action) |
Execute an action inside a temporary transaction on a worker thread. If no exception is thrown, the transaction will automatically be committed. More... | |
Static Public Member Functions | |
static void | DeleteRealm (RealmConfiguration configuration) |
Deletes all the files associated with a realm. Hides knowledge of the auxiliary filenames from the programmer. More... | |
static Realm | GetInstance (string databasePath) |
Factory for a Realm instance for this thread. More... | |
static Realm | GetInstance (RealmConfiguration config=null) |
Factory for a Realm instance for this thread. More... | |
Public Attributes | |
bool | IsClosed => SharedRealmHandle.IsClosed |
Checks if database has been closed. More... | |
Properties | |
RealmConfiguration | Config [get] |
Configuration that controls the Realm path and other settings. More... | |
RealmChangedEventHandler | RealmChanged |
Triggered when a realm has changed (i.e. a transaction was committed) More... | |
RealmSchema | Schema [get] |
The RealmSchema instance that describes all the types that can be stored in this Realm. More... | |
A Realm instance (also referred to as a realm) represents a Realm database.
Warning: Realm instances are not thread safe and can not be shared across threads You must call GetInstance on each thread in which you want to interact with the realm.
RealmResults<dynamic> All | ( | string | className | ) |
Get a view of all the objects of a particular type
className | The type of the objects as defined in the schema. |
Because the objects inside the view are accessed dynamically, the view cannot be queried into using LINQ or other expression predicates.
Referenced by Realm.RemoveAll().
RealmResults<T> All< T > | ( | ) |
Extract an iterable set of objects for direct use or further query.
T | The Type T must be a RealmObject. |
T | : | RealmObject |
Referenced by Realm.RemoveAll< T >().
Transaction BeginWrite | ( | ) |
Factory for a write Transaction. Essential object to create scope for updates.
using (var trans = myrealm.BeginWrite()) { var rex = myrealm.CreateObject<Dog>(); rex.Name = "Rex"; trans.Commit(); }
Referenced by Realm.Write().
void Close | ( | ) |
Closes the Realm if not already closed. Safe to call repeatedly. Note that this will close the file. Other references to the same database on the same thread will be invalidated.
References Realm.Dispose().
dynamic CreateObject | ( | string | className | ) |
Factory for a managed object in a realm. Only valid within a Write transaction.
className | The type of object to create as defined in the schema. |
If the realm instance has been created from an untyped 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
the returned object will be an instance of a user-defined class, as if created by
.
Referenced by Realm.CreateObject< T >().
T CreateObject< T > | ( | ) |
Factory for a managed object in a realm. Only valid within a Write transaction.
Using CreateObject is more efficient than creating standalone objects, assigning their values, then using Manage because it avoids copying properties to the realm.
T | The Type T must be a RealmObject. |
RealmOutsideTransactionException | If you invoke this when there is no write Transaction active on the realm. |
T | : | RealmObject | |
T | : | new() |
References Realm.CreateObject().
|
static |
Deletes all the files associated with a realm. Hides knowledge of the auxiliary filenames from the programmer.
configuration | A configuration which supplies the realm path. |
References RealmConfiguration.DatabasePath, and Realm.Schema.
void Dispose | ( | ) |
Dispose automatically closes the Realm if not already closed.
Referenced by Realm.Close().
override bool Equals | ( | Object | rhs | ) |
bool Equals | ( | Realm | rhs | ) |
Determines whether the specified Realm is equal to the current Realm.
true
if the Realms are functionally equal.References Realm.Config, RealmConfiguration.Equals(), and Realm.IsClosed.
override int GetHashCode | ( | ) |
Serves as a hash function for a Realm based on the core instance.
|
static |
Factory for a Realm instance for this thread.
databasePath | Path to the realm, must be a valid full path for the current platform, relative subdir, or just filename. |
If you specify a relative path, sandboxing by the OS may cause failure if you specify anything other than a subdirectory.
Instances are cached for a given absolute path and thread, so you may get back the same instance.
RealmFileAccessErrorException | Throws error if the filesystem has an error preventing file creation. |
References RealmConfiguration.ConfigWithPath(), and RealmConfiguration.DefaultConfiguration.
Referenced by Realm.GetInstance(), and Realm.WriteAsync().
|
static |
Factory for a Realm instance for this thread.
config | Optional configuration. |
RealmFileAccessErrorException | Throws error if the filesystem has an error preventing file creation. |
References RealmConfiguration.DatabasePath, RealmConfiguration.DefaultConfiguration, RealmConfiguration.EncryptionKey, Realm.GetInstance(), RealmConfiguration.MigrationCallback, RealmConfiguration.ObjectClasses, RealmConfiguration.ReadOnly, RealmConfiguration.SchemaVersion, and RealmConfiguration.ShouldDeleteIfMigrationNeeded.
bool IsSameInstance | ( | Realm | rhs | ) |
Determines whether this instance is the same core instance as the specified rhs.
You can, and should, have multiple instances open on different threads which have the same path and open the same Realm.
true
if this instance is the same core instance the specified rhs; otherwise, false
.void Manage< T > | ( | T | obj | ) |
This realm will start managing a RealmObject which has been created as a standalone object.
T | The Type T must not only be a RealmObject but also have been processed by the Fody weaver, so it has persistent properties. |
obj | Must be a standalone object, null not allowed. |
RealmOutsideTransactionException | If you invoke this when there is no write Transaction active on the realm. |
RealmObjectAlreadyManagedByRealmException | You can't manage the same object twice. This exception is thrown, rather than silently detecting the mistake, to help you debug your code |
RealmObjectManagedByAnotherRealmException | You can't manage an object with more than one realm |
T | : | RealmObject |
RealmObject ObjectForPrimaryKey | ( | string | className, |
Int64 | id | ||
) |
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
className | Name of class in dynamic situation. |
id | Id to be matched exactly, same as an == search. |
RealmClassLacksPrimaryKeyException | If the RealmObject class lacks an [PrimaryKey]. |
RealmObject ObjectForPrimaryKey | ( | string | className, |
string | id | ||
) |
Fast lookup of an object for dynamic use, from a class which has a PrimaryKey property.
className | Name of class in dynamic situation. |
id | Id to be matched exactly, same as an == search. |
RealmClassLacksPrimaryKeyException | If the RealmObject class lacks an [PrimaryKey]. |
T ObjectForPrimaryKey< T > | ( | Int64 | id | ) |
Fast lookup of an object from a class which has a PrimaryKey property.
T | The Type T must be a RealmObject. |
id | Id to be matched exactly, same as an == search. Int64 argument works for all integer properties supported as PrimaryKey. |
RealmClassLacksPrimaryKeyException | If the RealmObject class T lacks an [PrimaryKey]. |
T | : | RealmObject |
T ObjectForPrimaryKey< T > | ( | string | id | ) |
Fast lookup of an object from a class which has a PrimaryKey property.
T | The Type T must be a RealmObject. |
id | Id to be matched exactly, same as an == search. |
RealmClassLacksPrimaryKeyException | If the RealmObject class T lacks an [PrimaryKey]. |
T | : | RealmObject |
delegate void RealmChangedEventHandler | ( | object | sender, |
EventArgs | e | ||
) |
Handler type used by RealmChanged
sender | The Realm which has changed. |
e | Currently an empty argument, in future may indicate more details about the change. |
bool Refresh | ( | ) |
void Remove | ( | RealmObject | obj | ) |
Removes a persistent object from this realm, effectively deleting it.
obj | Must be an object persisted in this realm. |
RealmOutsideTransactionException | If you invoke this when there is no write Transaction active on the realm. |
System.ArgumentNullException | If you invoke this with a standalone object. |
void RemoveAll | ( | string | className | ) |
Remove all objects of a type from the realm.
className | Type of the objects to remove as defined in the schema. |
References Realm.All().
void RemoveAll | ( | ) |
Remove all objects of all types managed by this realm.
void RemoveAll< T > | ( | ) |
Remove all objects of a type from the realm.
T | Type of the objects to remove. |
T | : | RealmObject |
References Realm.All< T >().
void RemoveRange< T > | ( | RealmResults< T > | range | ) |
Remove objects matcing a query from the realm.
T | Type of the objects to remove. |
range | The query to match for. |
void Write | ( | Action | action | ) |
Execute an action inside a temporary transaction. If no exception is thrown, the transaction will automatically be committed.
Creates its own temporary transaction and commits it after running the lambda passed to action
. Be careful of wrapping multiple single property updates in multiple Write
calls. It is more efficient to update several properties or even create multiple objects in a single Write, unless you need to guarantee finer-grained updates.
realm.Write(() => { d = myrealm.CreateObject<Dog>(); d.Name = "Eddie"; d.Age = 5; });
action | Action to perform inside a transaction, creating, updating or removing objects. |
References Realm.BeginWrite().
Task WriteAsync | ( | Action< Realm > | action | ) |
Execute an action inside a temporary transaction on a worker thread. If no exception is thrown, the transaction will automatically be committed.
Opens a new instance of this realm on a worker thread and executes action
inside a write transaction. Realms and realm objects are thread-affine, so capturing any such objects in the action
delegate will lead to errors if they're used on the worker thread.
await realm.WriteAsync(tempRealm => { var pongo = tempRealm.All<Dog>().Single(d => d.Name == "Pongo"); var missis = tempRealm.All<Dog>().Single(d => d.Name == "Missis"); for (var i = 0; i < 15; i++) { var pup = tempRealm.CreateObject<Dog>(); pup.Breed = "Dalmatian"; pup.Mum = missis; pup.Dad = pongo; } });
action | Action to perform inside a transaction, creating, updating or removing objects. |
Task
so it can be used by await
.References Realm.Config, and Realm.GetInstance().
bool IsClosed => SharedRealmHandle.IsClosed |
|
get |
Configuration that controls the Realm path and other settings.
Referenced by Realm.Equals(), and Realm.WriteAsync().
|
addremove |
Triggered when a realm has changed (i.e. a transaction was committed)
|
get |
The RealmSchema instance that describes all the types that can be stored in this Realm.
Referenced by Realm.DeleteRealm().