本文整理汇总了C#中Realm.getTable方法的典型用法代码示例。如果您正苦于以下问题:C# Realm.getTable方法的具体用法?C# Realm.getTable怎么用?C# Realm.getTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Realm
的用法示例。
在下文中一共展示了Realm.getTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: execute
public override long execute(Realm realm, long version)
{
/*
// Version 0
class Person
@Required
String firstName;
@Required
String lastName;
int age;
// Version 1
class Person
@Required
String fullName; // combine firstName and lastName into single field.
int age;
*/
// Migrate from version 0 to version 1
if (version == 0)
{
Table personTable = realm.getTable(typeof(Person));
long fistNameIndex = getIndexForProperty(personTable, "firstName");
long lastNameIndex = getIndexForProperty(personTable, "lastName");
long fullNameIndex = personTable.addColumn(ColumnType.STRING, "fullName");
for (int i = 0; i < personTable.size(); i++)
{
personTable.setString(fullNameIndex, i, personTable.getString(fistNameIndex, i) + " " + personTable.getString(lastNameIndex, i));
}
personTable.removeColumn(getIndexForProperty(personTable, "firstName"));
personTable.removeColumn(getIndexForProperty(personTable, "lastName"));
version++;
}
/*
// Version 2
class Pet // add a new model class
@Required
String name;
@Required
String type;
class Person
@Required
String fullName;
int age;
RealmList<Pet> pets; // add an array property
*/
// Migrate from version 1 to version 2
if (version == 1)
{
Table personTable = realm.getTable(typeof(Person));
Table petTable = realm.getTable(typeof(Pet));
long nameColumnIndex = petTable.addColumn(ColumnType.STRING, "name");
long typeColumnIndex = petTable.addColumn(ColumnType.STRING, "type");
long petsIndex = personTable.addColumnLink(ColumnType.LINK_LIST, "pets", petTable);
long fullNameIndex = getIndexForProperty(personTable, "fullName");
for (int i = 0; i < personTable.size(); i++)
{
if (personTable.getString(fullNameIndex, i).Equals("JP McDonald"))
{
long rowIndex = petTable.addEmptyRow();
petTable.setString(nameColumnIndex, rowIndex, "Jimbo");
petTable.setString(typeColumnIndex, rowIndex, "dog");
personTable.getUncheckedRow(i).getLinkList(petsIndex).add(rowIndex);
}
}
version++;
}
/*
// Version 3
class Pet
@Required
String name;
int type; // type becomes int
class Person
String fullName; // fullName is nullable now
RealmList<Pet> pets; // age and pets re-ordered
int age;
*/
// Migrate from version 2 to version 3
if (version == 2)
{
Table personTable = realm.getTable(typeof(Person));
long fullNameIndex = getIndexForProperty(personTable, "fullName");
// fullName is nullable now.
personTable.convertColumnToNullable(fullNameIndex);
Table petTable = realm.getTable(typeof(Pet));
long oldTypeIndex = getIndexForProperty(petTable, "type");
long typeIndex = petTable.addColumn(ColumnType.INTEGER, "type");
for (int i = 0; i < petTable.size(); i++)
{
string type = petTable.getString(oldTypeIndex, i);
//.........这里部分代码省略.........