カスタムシリアライザーを持つエンティティがいくつかあります。
public class EntitySerializer : BsonBaseSerializer, IBsonIdProvider
{
public override object Deserialize(MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options){
...
bsonReader.ReadName(); // _id
ObjectId id = bsonReader.ReadObjectId();
...
}
public override void Serialize(MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
...
bsonWriter.WriteObjectId("_id", ent.Id);
...
}
}
....
BsonSerializer.RegisterSerializer(typeof(Entity), new EntitySerializer());
ここで、LINQ を介してこのエンティティをクエリしたいと思います。
GetEntityCollection().AsQueryable<Entity>().Where(d=>d.Id==new ObjectId("51b8939d3f92b82db4ad1db0"))
これにより、次のエラーが返されます
NotSupportedException: Unable to determine the serialization information for the expression: d.Id.
カスタムシリアライザーを使用していない場合、この動作は発生しないため、何かを忘れたり見逃したりしたと推測しています。インターネットを検索しても、エラーを解決できるものは何も得られませんでした。誰かが私に欠けているものを教えてもらえますか?
Google グループで提供された解決策: IBsonDocumentSerializer を実装します。