Try this, it works fine:
var peopleList = query.ToList()
peopleList.ForEach(p => Console.WriteLine(p));
peopleList.ForEach(p => Console.WriteLine(p.toJson()));
peopleList.ForEach(p => Console.WriteLine(p.Name));
The type of p
is, I believe, is anonymous. So, you can’t map it to something like PersonDTO
.
But, you can do this:
List<PersonDTO> dtoList = new List<PersonDTO>();
foreach (var p in peopleList)
{
dtoList.Add(new PersonDTO() { Name = p.Name, Age = p.Age });
}
Now, the dtoList
has the PersonDTO
objects.