我在 mongodb 中有这个 Bson 模型:
"setting|resources" : {
"Name" : "EsupHamrah",
"Id" : "449ea0e1-0261-4bee-b096-a838746c94ea",
"Children" : [..
我已经创建了这个契约(Contract)模型:
public class SettingResources
{
public string Name { get; set; }
[BsonElement]
//[BsonRepresentation(BsonType.String)]
public string Id { get; set; }
//[BsonId(IdGenerator = typeof(CombGuidGenerator))]
//public string Id { get; set; }
public IList<object> Children { get; set; }
}
当我查询时,我得到了这个错误:
An error occurred while deserializing the configs property of class ConsoleMongoApp.Applications: An error occurred while deserializing the values property of class ConsoleMongoApp.Configs: An error occurred while deserializing the resources property of class ConsoleMongoApp.Values: Element 'Id' does not match any field or property of class ConsoleMongoApp.SettingResources.
Id
只是字符串,不是 GUID 或 ObjectId 但为什么 mongo 不能映射 id?
最佳答案
你在mongodb中的模型是错误的,有一个| (管道)在 Json 字符串中,尝试在 "settingResources" 上修复它:
"settingResources" : {
"Name" : "EsupHamrah",
"Id" : "449ea0e1-0261-4bee-b096-a838746c94ea",
"Children" : [..
关于c#: 元素 'Id' 不匹配任何字段或属性 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49705340/