Я пытаюсь удалить объекты из базы данных области в приложении winForm dotnet, но мой код выдает мне эту ошибку
Возникло исключение: 'Realms.Exceptions.RealmInvalidObjectException' в Realm.dll Исключениетипа Realms.Exceptions.RealmInvalidObjectException произошла в Realm.dll, но не была обработана в коде пользователя. Попытка доступа к отдельной строке
Realm realm;
IQueryable<RObj> items;
public Form1()
{
InitializeComponent();
var config = new RealmConfiguration("DB.realm");
config.ShouldDeleteIfMigrationNeeded = true;
realm = Realm.GetInstance(config);
//WriteRealmTest();
}
private void Form1_Load(object sender, EventArgs e)
{
items = realm.All<RObj>();
listboxMain.DisplayMember = "title";
listboxMain.ValueMember = "id";
BindingSource bs = new BindingSource();
bs.DataSource = items;
listboxMain.DataSource = bs;
}
private void listboxMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
int index = listboxMain.SelectedIndex;
if (index < 0) { return; }
RObj item = items.ElementAt(index);
if (!item.IsValid)
return;
using (var trans = realm.BeginWrite())
{
realm.Remove(item);
trans.Commit(); //when this line is commented, no error is raised
}
}
}