i have in the database typical tables like user, usergroup, and they have relations.
in my domain-model i want that if you request users, you will get the users and each user has the property belongsto, which means these are the groups he belongs to. in the property i want to have the list of groups (typesafe as groups)
the same should be done on the other hand, that means each group should know which users belong to the group.
i have this classes (example):
public class User
{
int Id { get; set; }
string Name { get; set; }
List<Usergroup> BelongsTo { get; set; }
User()
{
BelongsTo = new List<Usergroup>();
}
}
public class Usergroup
{
int Id { get; set; }
string Name { get; set; }
List<User> Users { get; set; }
Usergroup()
{
Users = new List<User>();
}
}
internal class Relation
{
int userId;
int groupId;
}
now, whats the best way to implement it, and whats the fastest way to get all objects filled.
btw: i'm using subsonic to get all the database-records (for each table one select). and there are at least 1500 user and 30 groups.
my current code is based on foreach over the groups, relations.where for the groups, and then users.singleordefault to find the user and then add the user to the group and the group to the user. but it takes appx 30secs to do this.
my client-app is a webapp, so i store the results after all in a cached repository, thats why i'm doing it in this way!!