C# MongoDB.Driver 2.0.0-beta1 中缺少 SetRepresentation() 方法
Missing SetRepresentation() method in C# MongoDB.Driver 2.0.0-beta1
我正在使用最新的 C# driver for MongoDB。我知道它现在是测试版,但我认为我正在做一些基本的事情。
我的问题是什么:我正在尝试将我的 Id 字段的表示设置为 ObjectId
而不是 string
,就像 documentation:
中描述的那样
BsonClassMap.RegisterClassMap<Entity>(cm =>
{
cm.AutoMap();
cm.IdMemberMap.SetRepresentation(BsonType.ObjectId);
});
但我不能这样做,因为 SetRepresentation()
方法不存在。我找不到类似的东西。
所以我想知道,这个方法被删除了吗?
除了属性之外,还有其他方法可以设置表示吗?我无法使用属性,因为我无权访问实体 class,我正在使用派生的 class.
提前致谢!
我和驱动的开发者谈过了,他澄清了这个情况:
We've brought all those options into the serializers themselves, so, in this case, you'll want to set the serializer. IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); //It's a string which will be represented as an ObjectId in the database.
这对我有用 (v2.2)
cm.MapIdMember(c => c.Id)
.SetSerializer(new StringSerializer(BsonType.ObjectId))
.SetIdGenerator(StringObjectIdGenerator.Instance);
它表示数据库中的 objectId(不是字符串)
"_id" : ObjectId("56715ebddb6986202816e566"),
我正在使用最新的 C# driver for MongoDB。我知道它现在是测试版,但我认为我正在做一些基本的事情。
我的问题是什么:我正在尝试将我的 Id 字段的表示设置为 ObjectId
而不是 string
,就像 documentation:
BsonClassMap.RegisterClassMap<Entity>(cm =>
{
cm.AutoMap();
cm.IdMemberMap.SetRepresentation(BsonType.ObjectId);
});
但我不能这样做,因为 SetRepresentation()
方法不存在。我找不到类似的东西。
所以我想知道,这个方法被删除了吗? 除了属性之外,还有其他方法可以设置表示吗?我无法使用属性,因为我无权访问实体 class,我正在使用派生的 class.
提前致谢!
我和驱动的开发者谈过了,他澄清了这个情况:
We've brought all those options into the serializers themselves, so, in this case, you'll want to set the serializer. IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); //It's a string which will be represented as an ObjectId in the database.
这对我有用 (v2.2)
cm.MapIdMember(c => c.Id)
.SetSerializer(new StringSerializer(BsonType.ObjectId))
.SetIdGenerator(StringObjectIdGenerator.Instance);
它表示数据库中的 objectId(不是字符串)
"_id" : ObjectId("56715ebddb6986202816e566"),