I am using LiteDB 5.0.9.
I found the autoid will didn't work well after delete.
I read the source code and found a unit test about autoid after delete is AutoId_No_Duplicate_After_Delete(). But I think people will not often add data immediately after delete . So I change test like this, it wrong.
[Fact]
public void AutoId_No_Duplicate_After_Delete1()
{
// using strong type
using (var db = new LiteDatabase("database.db"))
{
var col = db.GetCollection<EntityInt>("col1");
var one = new EntityInt { Name = "One" };
var two = new EntityInt { Name = "Two" };
// insert
col.Insert(one);
col.Insert(two);
one.Id.Should().Be(1);
two.Id.Should().Be(2);
// now delete first 2 rows
col.Delete(one.Id);
col.Delete(two.Id);
}
using (var db = new LiteDatabase("database.db"))
{
var col = db.GetCollection<EntityInt>("col1");
var three = new EntityInt { Name = "Three" };
var four = new EntityInt { Name = "Four" };
// and insert new documents
col.Insert(new EntityInt[] { three, four });
three.Id.Should().Be(3);
four.Id.Should().Be(4);
}
}
The error message is Expected three.Id to be 3, but found 1..
I found this issue in a real live situation.
It would be great if this could be fixed and that the auto increment is not decreased after a delete operation.
I am using LiteDB 5.0.9. I found the autoid will didn't work well after delete.
I read the source code and found a unit test about autoid after delete is
AutoId_No_Duplicate_After_Delete()
. But I think people will not often add data immediately after delete . So I change test like this, it wrong.The error message is
Expected three.Id to be 3, but found 1.
.