c#: 元素 'Id' 不匹配任何字段或属性 MongoDB

标签 c# mongodb

我在 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/

相关文章:

javascript - mongodb 驱动程序不释放资源

javascript - 异步访问 DOM 元素而不挂起 UI

c# - 从 C# 项目导航到 VB.NET 项目中的类或方法时,有没有办法阻止显示 C# 元数据

java - 使用 elem 对子文档数组进行 Morphia 查询

node.js - 如何在 Mongoose 中创建一个自动字段?

javascript - Apollo /GraphQL : How to get nested elements?

node.js - Nodejs如何发布多个数组

c# - 静态析构函数

c# - 扩展 ASP.NET 面板

c# - 在C#中使用基本身份验证调用WEB API