首页 > 解决方案 > 未找到创作者

问题描述

你能帮忙解决这个问题吗,当我使用 mongodb c# 驱动程序从 mongodb 检索数据时,我遇到了No Creator Found问题。

这是我使用的模型类

[BsonIgnoreExtraElements]
class Employee
{

    [BsonElement("name")]
    public string Name { get; set; }

    [BsonElement("gender")]
    public string Gender { get; set; }

    [BsonElement("city")]
    public string City { get; set; }

    [BsonElement("country")]
    public string Country{get;set;}
}

我正在反序列化

var _ListofEmployees = (from emp in _IMongoCollection<Employee>.AsQueryable()

                                select new
                                {
                                    Name = emp.Name,
                                    City = emp.City

                                });

            foreach (var Employee in _ListofEmployee) 
            {
              Console.WriteLine("Name :"+Employee.Name+"\n"+"City :"+Employee.City);
            }

注意: mongodb 集合的文档中不存在 Country 字段

标签: c#mongodbmongodb-.net-driver

解决方案


推荐阅读