【问题标题】:Update property for Realm entry更新领域条目的属性
【发布时间】:2018-10-28 14:33:59
【问题描述】:

我在 Xamarin 项目中使用 Realm 数据库

我有这个模型的领域对象

public class UserModel: RealmObject
{
    public string Id { get; set;}
    public string Email { get; set; }
    public string Password { get; set; }
    public byte[] UserAvatar { get; set; }
    public string ApiKey { get; set; }
    public string Name { get; set; }
    public string Surname { get; set; }
    public string Birthday { get; set; }
    public int Country_id { get; set; }
    public bool IsAuthorized { get; set; }
    public string Base64Avatar { get; set; }
    public string Telephone { get; set; }
}

我需要更新Name 属性。

我如何尝试这样做

var realm = Realm.GetInstance();
var user_check = realm.All<UserModel>().First(); 
user_check.Name = "Test"

得到这个错误

我该如何解决这个问题?

【问题讨论】:

    标签: c# .net xamarin xamarin.ios realm


    【解决方案1】:

    必须在事务中添加/更新/删除 Realm 对象,最简单的方法是将其包装在 Write 方法中。

    realm.Write(() => 
    {
        user_check.Name = "Test";
    });
    

    欲了解更多信息,请查看Rleam Write docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多