i wrote a while loop to find each person file number from a table and add it inside another class array but for some reason, it returns an Object reference not set to an instance of an object ERROR. Here is My Class
public class Person
{
public string IDENTITY { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public class Exam[] Exams;
public string Data { get; set; }
}
public class Exam
{
public string IDENTITY
public string Name
public int Pass_Score
public int Score
public string Grade
}
and I have a table for person and table for Exam, My Goal is to Connect each person with all the exams he has in the exam table to return it as XML file.
[ResponseType(typeof(Person))]
public async Task<IHttpActionResult> GetPerson(string id)
{
Person p = await db.Person.FindAsync(id);
int count = db.Exam.Count();
Exam fS = new Exam();
int i = 0;
while (i < count) {
if (fS.IDENTITY.Equals(p.IDENTITY)) {
Exam e = new Exam();
e.IDENTITY = fS.IDENTITY;
e.Name= fS.Name;
e.Pass_Score = fS.Pass_Score ;
e.Grade= fS.Grade;
e.Score = fS.Score ;
i++;
};
}
if (p== null)
{
return NotFound();
}
return Ok(p);
}
My Guess's the Error Comes from inside the While loop?