Supposed I have two classes like this:
public class Parent
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public IList<Child> Children { get; set; }
...
}
public class Child
{
public string Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string Age { get; set; }
...
}
If I want to serialize some properties of Parent I can do like this:
var data = GetListOfParents();
return Json(data.Select(x => new { x.Id, x.Name}));
If I want to get the list of parents as above but each Parent contains one list of Children with selected properties like Id and Name only, what is the proper way to do it?
I don’t want to use [ScriptIgnore] because my entities contain a lot of Properties.
Thank you
You could do it like this: