LiteDB Deserialization Leaves Vogen Value Objects Uninitialized
Describe the bug
Hi, I am using Rider and I have tested and found the issue both on a Unit Tests Project and a Blazor project.
When using Vogen value objects with LiteDB, deserialization doesn’t work correctly. Specifically, after retrieving an entity from LiteDB, inspecting the deserialized Vogen value object (e.g., CustomerId) shows it as UNINITIALIZED in all caps.
Actual Behavior
The deserialized CustomerId appears as UNINITIALIZED when inspected, indicating LiteDB fails to properly initialize the value object.
Steps to reproduce
- Define a Vogen value type:
[ValueObject<int>] public readonly partial struct CustomerId { } - Use it in an entity:
public class MyEntity { public CustomerId Id { get; set; } } - Insert an instance into LiteDB (v5.x) and retrieve it using the default liteDb way
// similar to this
var collection = _db.GetCollection<T>(collectionName);
var bsonId = new BsonValue(id);
var entity = collection.FindById(bsonId);
Expected behaviour
The deserialized CustomerId should contain the correct int value stored in LiteDB.
I quickly threw together a basic generator that seems to work with LiteDB. All the code is in one file. It could help address the issue. Check out Primify
Thanks for the contribution @koddek ! I'll add this soon.