Hi,
I have a very simple problem for which though I have a solution but I want to know how others tackle it effectively.
Assume we have a User table, and a Role table. Each user can have multiple roles and vice-versa (many-to-many relationship). This relationship is stored in a cross table: UserRoleMapper (UserID, RoleID).
Now I have to get a list of all users, with their role names too. But if I have a user belonging to 3 different roles, I will get that user 3 times in a list. What is the best way to handle such scenarios? One simple way is to get all users first, and then fire another query (another hit to the DB) to get their respective roles. Is there any other solution better than this?
thanks,