I have database and I'm using Entity Framework to create models (database first). I want to loop somehow through my model so that I can create a list of each row. Then I want to create list of those lists. Also lists have to be lists of objects not strings.
Model class:
public class person
{
public int ID {get; set;}
public string Code {get; set;}
public int Time {get; set;}
public string Name {get; set;}
}
Now I have such a person in the database and I want to create a list that contains ID, Code, Time and Name taken from one row. And then I want to create a list of those Person lists. I assume that I should use foreach or for loop but I don't know how should I start.
Edit: I have database that looks like this:
ID | Code | Time | Name
1 200 10 Paul
2 201 20 Tom
3 203 25 Jacob
4 208 10 Agnes
Now i want to create a list with one row. That list should look like:
List<1,200,10,Paul>
Then i want to create or rather add to list of lists each list created from those rows. So that i would have list that contains lists of Persons.
context.Persons.ToList();This will return aList<Person>. You would use foreach in your view to loop through that list.List<Person>. It seems to me you are using MVC. So in your controller GET you would fill a list of persons from the context as shown. Then you would pass and display this in a View with foreach. More info needed...List<List<Person>>, what is inside eachList<Person>that separates it from the others?