Realm Xamarin  v0.74.1
Realm for Xamarin
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
Realm Class Reference

A Realm instance (also referred to as a realm) represents a Realm database. More...

Inherits IDisposable.

Public Member Functions

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. More...
 
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...
 
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 ()
 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...
 

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

Detailed Description

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.

Member Function Documentation

RealmResults<T> All< T > ( )

Extract an iterable set of objects for direct use or further query.

Template Parameters
TThe Type T must not only be a RealmObject but also have been processd by the Fody weaver, so it has persistent properties.
Returns
A RealmResults that without further filtering, allows iterating all objects of class T, in this realm.
Type Constraints
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(); }

Returns
A transaction in write mode, which is required for any creation or modification of objects persisted in a Realm.

Referenced by Realm.Write().

void Close ( )

Closes the Realm if not already closed. Safe to call repeatedly.

Referenced by Realm.Dispose().

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.

Template Parameters
TThe Type T must not only be a RealmObject but also have been processd by the Fody weaver, so it has persistent properties.
Returns
An object which is already managed.
Exceptions
RealmOutsideTransactionExceptionIf you invoke this when there is no write Transaction active on the realm.
Type Constraints
T :RealmObject 
T :new() 

References Realm.Config, and RealmConfiguration.ObjectClasses.

static void DeleteRealm ( RealmConfiguration  configuration)
static

Deletes all the files associated with a realm. Hides knowledge of the auxiliary filenames from the programmer.

Parameters
configurationA configuration which supplies the realm path.

References RealmConfiguration.DatabasePath.

Referenced by Realm.GetInstance().

void Dispose ( )

Dispose automatically closes the Realm if not already closed.

References Realm.Close().

override bool Equals ( Object  rhs)

Generic override determines whether the specified System.Object is equal to the current Realm.

Parameters
rhsThe System.Object to compare with the current Realm.
Returns
true if the Realms are functionally equal.
bool Equals ( Realm  rhs)

Determines whether the specified Realm is equal to the current Realm.

Parameters
rhsThe Realm to compare with the current Realm.
Returns
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.

Returns
A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.
static Realm GetInstance ( string  databasePath)
static

Factory for a Realm instance for this thread.

Parameters
databasePathPath 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.

Returns
A realm instance, possibly from cache.
Exceptions
RealmFileAccessErrorExceptionThrows error if the filesystem has an error preventing file creation.

References RealmConfiguration.ConfigWithPath(), and RealmConfiguration.DefaultConfiguration.

static Realm GetInstance ( RealmConfiguration  config = null)
static

Factory for a Realm instance for this thread.

Parameters
configOptional configuration.
Returns
A realm instance.
Exceptions
RealmFileAccessErrorExceptionThrows error if the filesystem has an error preventing file creation.

References Realm.Config, RealmConfiguration.DefaultConfiguration, Realm.DeleteRealm(), RealmConfiguration.ObjectClasses, Realm.RealmChanged, Realm.RealmChangedEventHandler(), and RealmConfiguration.SchemaVersion.

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.

Returns
true if this instance is the same core instance the specified rhs; otherwise, false.
Parameters
rhsThe Realm to compare with the current Realm.
void Manage< T > ( obj)

This realm will start managing a RealmObject which has been created as a standalone object.

Template Parameters
TThe Type T must not only be a RealmObject but also have been processd by the Fody weaver, so it has persistent properties.
Parameters
objMust be a standalone object, null not allowed.
Exceptions
RealmOutsideTransactionExceptionIf you invoke this when there is no write Transaction active on the realm.
RealmObjectAlreadyManagedByRealmExceptionYou can't manage the same object twice. This exception is thrown, rather than silently detecting the mistake, to help you debug your code
RealmObjectManagedByAnotherRealmExceptionYou can't manage an object with more than one realm
Type Constraints
T :RealmObject 
delegate void RealmChangedEventHandler ( object  sender,
EventArgs  e 
)

Handler type used by RealmChanged

Referenced by Realm.GetInstance().

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.

Returns
Whether the realm had any updates. Note that this may return true even if no data has actually changed.
void Remove ( RealmObject  obj)

Removes a persistent object from this realm, effectively deleting it.

Parameters
objMust be an object persisted in this realm.
Exceptions
RealmOutsideTransactionExceptionIf you invoke this when there is no write Transaction active on the realm.
System.ArgumentNullExceptionIf you invoke this with a standalone object.
void RemoveAll ( )

Remove all objects of all types managed by this realm.

References Realm.Config, and RealmConfiguration.ObjectClasses.

void RemoveAll< T > ( )

Remove all objects of a type from the realm.

Template Parameters
TType of the objects to remove.
Type Constraints
T :RealmObject 

References Realm.All< T >().

void RemoveRange< T > ( RealmResults< T >  range)

Remove objects matcing a query from the realm.

Template Parameters
TType of the objects to remove.
Parameters
rangeThe query to match for.
Type Constraints
T :RealmObject 
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; });

Parameters
actionAction to perform inside a transaction, creating, updating or removing objects.

References Realm.BeginWrite().

Member Data Documentation

bool IsClosed => SharedRealmHandle.IsClosed

Checks if database has been closed.

Returns
True if closed.

Referenced by Realm.Equals().

Property Documentation

RealmConfiguration Config
get

Configuration that controls the Realm path and other settings.

Referenced by Realm.CreateObject< T >(), Realm.Equals(), Realm.GetInstance(), and Realm.RemoveAll().

RealmChangedEventHandler RealmChanged
addremove

Triggered when a realm has changed (i.e. a transaction was committed)

Referenced by Realm.GetInstance().