I am trying to match my model code with the same structure as my json file. The json file has jsonArray which works fine as ReportList if accountlist (another array inside array items) did not exist.
Now I am trying to make it work with account list. So I created MyListType which matches the structure of accountlist in the json file.
Unfortunately, I am getting an error saying accountlist in json file does not match any field or property of Report class. (which I think should be matching with MyListType) Please help me to resolve this error. Thanks in advance.
The Model code
public class Report
{
public Object _id { get; set; }
public string username { get; set; }
public List<MyListType> accountlist{get; set;}
}
public class MyListType
{
public string address1 {get; set;}
public string address2 {get; set;}
}
Partial Controller Code
MongoCollection<Report> collection = Context.Database.GetCollection<Report>("report");
var ReportList = new List<Report>();
//Right below I get: Errors out here Element 'accountlist' does not match any field or //property of class MyProject.Models.Report.
foreach (Report doc in collection.FindAll())
{
ReportList.Add(doc);
}
report collection
{
"username" : "doodle",
"accountlist" : [
{"address1": "abc st", "address2": "efg st"},
{"address1": "hijk st", "address2": "mno st"}
]
}
{
"username" : "doodle2",
"accountlist" : [
{"address1": "abc st", "address2": "efg st"},
{"address1": "hijk st", "address2": "mno st"}
]
}