Search Results for

    Show / Hide Table of Contents

    Class Migration

    This class is given to you when you migrate your database from one version to another. It contains two properties: OldRealm and NewRealm. The NewRealm is the one you should make sure is up to date. It will contain models corresponding to the configuration you've supplied. You can read from the OldRealm and access properties that have been removed from the classes by using the dynamic API.

    Inheritance
    Object
    Migration
    Namespace: Realms
    Assembly: Realm.dll
    Syntax
    public class Migration

    Properties

    | Improve this Doc View Source

    NewRealm

    Gets the Realm that you should modify and make sure is up to date.

    Declaration
    public Realm NewRealm { get; }
    Property Value
    Type Description
    Realm

    The Realm that will be saved after the migration.

    | Improve this Doc View Source

    OldRealm

    Gets the Realm as it was before migrating. Use the dynamic API to access it.

    Declaration
    public Realm OldRealm { get; }
    Property Value
    Type Description
    Realm

    The Realm before the migration.

    Methods

    | Improve this Doc View Source

    RemoveType(String)

    Removes a type during a migration. All the data associated with the type, as well as its schema, will be removed from Realm.

    Declaration
    public bool RemoveType(string typeName)
    Parameters
    Type Name Description
    String typeName

    The type that needs to be removed.

    Returns
    Type Description
    Boolean

    true if the type does exist in the old schema, false otherwise.

    Remarks

    The removed type will still be accessible from OldRealm in the migration block. The type must not be present in the new schema. RemoveAll<T>() can be used on NewRealm if one needs to delete the content of the table.

    | Improve this Doc View Source

    RenameProperty(String, String, String)

    Renames a property during a migration.

    Declaration
    public void RenameProperty(string typeName, string oldPropertyName, string newPropertyName)
    Parameters
    Type Name Description
    String typeName

    The type for which the property rename needs to be performed.

    String oldPropertyName

    The previous name of the property.

    String newPropertyName

    The new name of the property.

    Examples
    // Model in the old schema
    class Dog : RealmObject
    {
        public string DogName { get; set; }
    }
    
    // Model in the new schema
    class Dog : RealmObject
    {
        public string Name { get; set; }
    }
    
    //After the migration Dog.Name will contain the same values as Dog.DogName from the old realm, without the need to copy them explicitly
    var config = new RealmConfiguration
    {
        SchemaVersion = 1,
        MigrationCallback = (migration, oldSchemaVersion) =>
        {
            migration.RenameProperty("Dog", "DogName", "Name");
        }
    };

    See Also

    See more in the migrations section in the documentation.
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2020 Realm
    Generated by DocFX