I want to get all users that have a specific role to a list of usernames.
Is using .Include to include all the users, and going through the UsersReference the best way to loop through all the users that are associated with the role?
I noticed I could not do a foreach(User user in role.Users) but UsersReference seem to work, but is that how it's supposed to be done? Going through the reference?
using (var context = new MyEntities())
{
List<string> users = new List<string>();
Role role = (from r in context.Roles.Include("Users")
where r.RoleName == roleName
select r).FirstOrDefault();
foreach (User user in role.UsersReference)
users.Add(user.UserName);
return users.ToArray();
}