问题标签 [bsonserializer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
80 浏览

c# - C# MongoDB BsonDocument 未使用 BsonSerializer 序列化为自定义类

我在使用 BsonSerializer 序列化 BsonDocuments 时遇到问题。

我正在使用var bsonDoc = collection.Find(...)从 MongoDB 数据库中提取单个文档。然后我尝试使用序列化它 var strongTypedDocument = BsonSerializer.Deserialize<MainSDocument>(bsonDoc);

这是 BsonDocument

这是 C# 类

我得到的错误是:FormatException: An error occurred while deserializing the GDetails property of class MainState : Element 'Id' does not match any field or property of class GDetails .'

为什么会这样?为什么该元素与类中Id的 int 元素不匹配?IdGDetails