I'm amateur with mongodb and C# driver. I try to Insert a document with array of sub-documents by class. my codes are these: This is my classes:
public class Entity
{
public string name { get; set; }
public string family { get; set; }
public List<sc> score { get; set; }
}
public class sc
{
public int Math{ get; set; }
public int literature{ get; set; }
}
And this is my code for fill fields and insert document:
var en = new Entity();
var sc1 = new sc();
var sc2 = new sc();
sc1.Math= 14;
sc1.literature= 15;
sc2.Math= 16;
sc2.literature= 19;
en.score[0] = sc1;
en.score[1] = sc2;
en.name = "Esi";
en.family = "Moja";
collection.Insert(en);
But i get this error when i run it:
Object reference not set to an instance of an object.
How can i fix this problem? Please help me.