我有以下设置,它可以工作,但是当MongoDB集合有额外的字段时,程序会崩溃并显示错误信息:“System.FormatException:元素'FriendName'与MyApp.User类中的任何字段或属性都不匹配”。我认为MongoDB驱动程序只能映射在C#类中声明的字段。是否有解决方法?谢谢。 MongoDB - 集合。
{ Name: "Allen" , Age: 22, Address: "Sample Address", FriendName = "Sue"}
public class User
{
public string Name {get;set;}
public int Age {get; set;}
public string Address {get;set; }
}
_db.GetCollection<User>("User").Find(f => f.Name == "Allen").FirstOrDefault();