System.FormatException:'元素'部门'与Models.Person类的任何字段或属性都不匹配。

时间:2019-07-04 09:11:45

标签: c# .net mongodb

我有一个Person类和两个派生类EmployeeManager

 public class Person
    {
        [BsonElement("_Id")]
        [BsonIgnoreIfDefault]
        public ObjectId Id; // matches "_ID" in the database        
        public ContactEnum ContactType { get; set; }
        public String FirstName { get; set; }
        public String LastName { get; set; }
        [BsonIgnore]
        public String Notes { get; set; }
    }



   public class Employee : Person
    {
        public String Department { get; set; }

        public Employee()
        {
            this.ContactType = ContactEnum.Employee;
        }
    }   


  public class Manager : Person
    {
        public String Group{ get; set; }

        public Manager()
        {
            this.ContactType = ContactEnum.Manager;
        }
    }       

当我尝试使用以下命令从MongoDB获取所有记录时:

 public async Task<IEnumerable<Person>> GetContacts()
        {
            try
            {
                var items = await db.Person.Find(_ => true).ToListAsync();

                return items;
            }
            catch (Exception ee)
            {
                throw;
            }
        }   

我明白了:System.FormatException: 'Element 'Department ' does not match any field or property of class Models.Person.'

任何想法我该如何解决?

0 个答案:

没有答案