我打算将所有实体保存在提供实际对象的通用元数据的相同“容器”对象中。例如:
public class Entity<T> where T : class
{
public Guid Id { get; set; }
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
//... and others...
public T Value { get; set; }
}
public class Foo
{
public string Name { get; set; }
public int Age { get; set; }
// ...and so on...
}
将按如下方式保存实体:
{
"_id": UUID("xxxxx...xxxx"),
"createdTime": "2019-01-01T00:00:00.000z",
"value": {
"name": "foo",
"age": 42,
}
}
我想像这样序列化(/反序列化):
{
"_id": UUID("xxxxx...xxxx"),
"_createdTime": "2019-01-01T00:00:00.000z",
"name": "foo",
"age": 42,
}
(createdTime
也更改为_createdTime
)
我不确定是否可以使用IBsonSerializer
或IBsonDocumentSerializer
来做到这一点。