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

前端 未结 3 461
暖寄归人
暖寄归人 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 11:14

    I already made it having this code :) thanks to @EpicPandaForce 's answer.

        public void deleteFromDatabase(int denom_ID, int form_ID)
        {            
            //Realm realm;
            //and
            //RealmConfiguration config = new RealmConfiguration(dbPath, true);
            //was initialized at the top of my class
    
            realm = Realm.GetInstance(config);
    
            realm.Write(() =>
            {
                var cashflow_denom = realm.All().Where(c => c.denom_id == denom_ID);
                var cashflow_form = realm.All().Where(c => c.form_id == form_ID);
    
                realm.RemoveRange(((RealmResults)cashflow_denom));
                realm.RemoveRange(((RealmResults)cashflow_form));
            });
        }
    

    it is now deleting my data without exception :)

提交回复
热议问题