MongoDb插入将我的布尔值设置为False

时间:2018-10-01 16:40:47

标签: c# .net mongodb boolean

在事件源应用程序中,我具有类似于以下内容的仓库模型:

    public Guid WarehouseId { get; set; }
    public string WarehouseName { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Address { get; set; }
    public int ZipCode { get; set; }
    public string Country { get; set; }
    public string PhoneNumber { get; set; }
    public DateTime ModifiedDate { get; set; }
    public double TotalSpace { get; set; }
    public double? UsedSpace { get; set; }
    public bool TemporaryWarehouse { get; set; }  //FLAG IN QUESTION! 
    public int? TotalBoxesAtLocation { get; set; }
    public int? UniqueBoxesAtLocation { get; set; }
    public int EventVersion { get; set; }
    public int EventsRun { get; set; }
    [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] // TODO: what is the best mongo dict representation for these?
    public Dictionary<string, int> Locations { get; set; } // tracks warehouse locations and asset count at each location key=loc value=count
    [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)]
    public Dictionary<int, List<string>> BoxTypeMap { get; set; } // boxTypeNum, list<location> - Can have duplicate locations indicating higher quantity at that location
    [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)]
    public Dictionary<Guid, string> BoxMap { get; set; } // maps individual boxGuid to current location

创建仓库后,可以通过将TemporaryWarehouse bool字段设置为true来将其创建为临时仓库。

作为此事件来源应用程序的一部分,可以通过重播事件来重建读取方数据库。执行此操作时,将同步处理仓库创建的事件,并重新创建仓库。

这里的问题是,即使事件数据包含将仓库设置为临时的必要标志(请参见下文),并且即使该数据已正确序列化为上述模型(在所有模型中都设置了TemporaryWarehouse标志)情况),在插入我的文档数据库后,该字段始终为false

这是怎么回事?

这是我的Warehouse插入方法:

    public void InsertWarehouseState(WarehouseState s)
    {
        _context.WarehouseState.InsertOne(s);
    }

在下面的图片中,您可以从仅在重建期间运行的此方法中看到临时仓库标志设置为true。此插入完成后,从mongo文档查看器查看时,该值为false。

enter image description here

要注意的另一件事是,在重播/重建之外,可以将仓库状态保存为临时的,没有问题。这只是重建期间的问题。

0 个答案:

没有答案