无法确定“表达式”的序列化信息

时间:2019-05-07 20:02:55

标签: mongodb mongodb-.net-driver

当我尝试更新文档时,收到错误消息无法确定=> a.CurrentProcessingStep 的序列化信息。

我正在使用Mongo .NET驱动程序2.8版和.NET Framework 4.7.2。

我正在使用库中的构建器助手来构建过滤器和更新语句。

这是我的文档类的相关部分:

    [BsonIgnoreExtraElements]
    [DebuggerDisplay("{Term}, Rule Status = {_ruleStatus}, Current Step = {_currentProcessingStep}")]
    public class SearchTermInfo : AMongoConnectedObject
    {
        [BsonElement("CurrentProcessingStep")]
        private ProcessingStep _currentProcessingStep;

        [BsonElement("RuleStatus")]
        private RuleStatus _ruleStatus;

        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime AddDateTime { get; set; }

        [BsonIgnore]
        [JsonIgnore]
        public ProcessingStep CurrentProcessingStep
        {
            get => _currentProcessingStep;
            set => AddHistoryRecord(value);
        }

        [BsonIgnore]
        [JsonIgnore]
        public RuleStatus RuleStatus
        {
            get => _ruleStatus;
            set => AddHistoryRecord(value);
        }

我正在使用以下代码构建过滤器:

FilterDefinition<SearchTermInfo> filter = Builders<SearchTermInfo>.Filter.And(
                Builders<SearchTermInfo>.Filter.Eq(a => a.Id, recordId),
                Builders<SearchTermInfo>.Filter.Or(
                    Builders<SearchTermInfo>.Filter.Eq(a => a.CurrentProcessingStep, currentStep),
                    Builders<SearchTermInfo>.Filter.Exists("CurrentProcessingStep", false)
                )
            );

然后我执行更新:

UpdateResult results =
                    searchTermInfoCollection.MongoCollection.UpdateOne(filter, update, null, cancellationToken);

我得到这个错误:

? ex
{"Unable to determine the serialization information for a => a.CurrentProcessingStep."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233079
    HelpLink: null
    InnerException: null
    Message: "Unable to determine the serialization information for a => a.CurrentProcessingStep."
    Source: "MongoDB.Driver"
    StackTrace: "   at MongoDB.Driver.ExpressionFieldDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry, Boolean allowScalarValueForArrayField)
    at MongoDB.Driver.SimpleFilterDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)\r\n
    at MongoDB.Driver.OrFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)\r\n   
    at MongoDB.Driver.AndFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.ConvertWriteModelToWriteRequest(WriteModel`1 model, Int32 index)\r\n   
    at System.Linq.Enumerable.<SelectIterator>d__5`2.MoveNext()\r\n   
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   
    at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation..ctor(CollectionNamespace collectionNamespace, IEnumerable`1 requests, MessageEncoderSettings messageEncoderSettings)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.CreateBulkWriteOperation(IEnumerable`1 requests, BulkWriteOptions options)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass23_0.<BulkWrite>b__0(IClientSessionHandle session)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)\r\n   
    at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)\r\n   
    at MongoDB.Driver.MongoCollectionBase`1.UpdateOne(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, Func`3 bulkWrite)\r\n   
    at MongoDB.Driver.MongoCollectionBase`1.UpdateOne(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, CancellationToken cancellationToken)\r\n   
    at SaFileIngestion.FileProcessorEngine.LockRecord(Int64 recordId, ProcessingStep currentStep, CancellationToken cancellationToken) 
    in D:\\[File Path]\\SaFileIngestion\\FileProcessorEngine.cs:line 195"
    TargetSite: {MongoDB.Driver.RenderedFieldDefinition`1[TField] Render(MongoDB.Bson.Serialization.IBsonSerializer`1[TDocument], MongoDB.Bson.Serialization.IBsonSerializerRegistry, Boolean)}

我还尝试使用以下代码构建过滤器:

 Builders<SearchTermInfo>.Filter.Eq("CurrentProcessingStep", currentStep),

给我的印象是,即使私有字段被标记为BsonIgnore,我也应该能够使用属性访问器来构建表达式,因为私有字段已使用与被忽略的属性访问器同名的BsonElementAttribute进行了命名。 >

我们对提供的任何指导表示赞赏。

谢谢

1 个答案:

答案 0 :(得分:-2)

我最终解决了这个问题。我不记得一年多以前的确切解决方案。我确实记得查询的构造方式有问题。