这是我的代码:
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[]]'.
为什么会发生这种情况,我该如何解决?
谢谢!