0

Is there any ways to detect differences between model and LiteDb?

For example.

[Table('table')]
public class Table
{
   public int Id { get; set; }
   public string Name { get; set; }
}

And liteDb has table with the same columns.

I wanna add a new property into my model

[Table('table')]
public class Table
{
  public int Id { get; set; }
  public string Name { get; set; }
  public string NewCol { get; set; }
}

How can I detect that NewCol is recently added into model and there no equal column into LiteDb table

Atlantis
  • 725
  • 7
  • 26

1 Answers1

1

There is no way to detect this change on model because for LiteDB engine, both classes are converted into BsonDocument, a generic object representation to be converted into JSON/BSON to store on disk. In your example, if you insert document with your first model, LiteDB convert to:

{ Id: 1, Name: "John" }

In second model, you will have:

{ Id: 1, Name: "John", NewCol: "anyvalue" }

In both cases you can load/save data because missing properties are defined as NULL.

But, if you need track database model version, you can use internal "UserVersion" for this. It's a simple internal int get/set value that you can track database model version. You can check this issue for more information: https://github.com/mbdavid/LiteDB/issues/778

mbdavid
  • 1,076
  • 7
  • 8