I am trying to serialize the data of courses. I get course id(C_id) and course Name(C_Name). I am getting one more thing that is Icoolection of students. When I try to serialize this, I am not able to get the nested list of students who have enrolled for the course.
var u = (from g in t.courses
select g)
.ToList();
List<course> ui = u
.Select(d => new course()
{ C_Name = d.C_Name,
C_Id = d.C_Id,
student = d.student
})
.ToList();
ASCIIEncoding objASCIIEncoding = new ASCIIEncoding();
string strData = JsonConvert
.SerializeObject(ui, Formatting.Indented, new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
});
In the above code I am getting proper data with nested students
list but when this line
string strData = JsonConvert.SerializeObject(ui, Formatting.Indented, new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
});
executes I only get Course ID(C_ID) and course Name(C_Name) . The nested student
list is not serialized.