使用Mongo 2.2驱动程序列出objectid列表 - C#

时间:2015-12-20 09:49:20

标签: c# mongodb exception filter

这是我的代码:

public IList<ConversationDescriptor> GetPersonalConversations(ObjectId author)
{
        var authorArray = new ObjectId[] { author };
        var filter = Builders<ConversationDto>.Filter.AnyEq("ParticipantsIds",authorArray)
                                _conversationStorage.Find(filter).ToListAsync().Result
}

ConversationDto对象看起来像:

public class ConversationDto : BaseEntity<ObjectId>
{
    public ObjectId CreatorId { get; set; }

    public IList<ObjectId> ParticipantsIds { get; set; }

    public BsonDateTime StartDate { get; set; }

    public BsonDateTime Timestamp { get; set; }

    public bool IsSystemMessage { get; set; }
}

Builders<ConversationDto>.Filter.AnyEq("ParticipantsIds",authorArray) - 此过滤器会产生异常:

System.AggregateException : One or more errors occurred.
  ----> System.InvalidCastException : Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.ObjectIdSerializer' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[MongoDB.Bson.ObjectId[]]'.

为什么会发生这种情况,我该如何解决?
谢谢!

0 个答案:

没有答案