MongoDb C# 驱动程序正在将 List 成员的空值反序列化为空

MongDb C# Driver is deserialzing null values for a List member as empty

我在其中一个应用程序中使用 MongoDB 和 c# 驱动程序。 我定义了一个如下所示的实体,还定义了类映射来强制实施模式。

public class TestEntity
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public List<SomeModel> Properties { get; set; }
}

此外,我已经定义了禁用空或 null 序列化的约定 arrays/lists。

new ConventionPack { new IgnoreIfNullConvention(true)
conventionPack.Add(new IgnoreEmptyArraysConvention());

一切都按预期工作,但是当我像下面这样使用 c# 驱动程序查询文档时,我得到的属性是一个空列表而不是 null。

Database.GetCollection<TestEntity>("test").Find(filter, findOptions).FirstOrDefault()

例如,如果我有如下的 testentity 文档,当我使用 c# 驱动程序查询时 "Properties" 属性 返回为空列表而不是 null。

{ “_id”:ObjectId(“5991be3475f14655406cd301”), "name": "test", "description": "test" }

我在网上搜索时找不到答案。希望有人能帮忙。谢谢

删除约定 IgnoreEmptyArraysConvention 查看代码 here 似乎它创建了一个列表的新实例。