My code is working however i am trying to find a more efficient way to accomplish this. Like a linq solution without the foreach loop something that would be better. I dont have any performance issues..
List<Table> tables = getTables();
foreach (TableCategories category in categories)
{
category.Tables=tables.FindAll(tbl => tbl.CategoryId == category.Id);
}
For database i use pure ADO.NET not linq as i am using postgres.
How about:
This is more efficient (assuming you have a lot of tables) because you build a lookup at the beginning in O(n) time, and then each lookup in the for loop is O(1) time, so you end up with O(m + n) instead of O(m*n) complexity.