C# - how to delete row in realm - android xamarin

前端 未结 3 422
暖寄归人
暖寄归人 2021-01-28 10:35

i tried this method that I created but it prompts me an error:

Realms.RealmInvalidObjectException:This object is detached. Was it deleted from the realm?\'

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 10:54

    public void deleteFromDatabase(Realm realm, long cashDenominatorId)
    {
        realm.Write(() => 
        {
             var cashDenominator = realm.All().Where(c => c.Id == cashDenominatorId);
             Realm.RemoveRange(((RealmResults)cashDenominator));
        });
    }
    

    Which you would call as

    Realm realm = Realm.GetInstance(config);
    var denom_list = ...
    // ...
    deleteFromDatabase(realm, denom_list[0].id);
    

提交回复
热议问题