|
-
Jul 8th, 2012, 04:13 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] LINQ for converting IList<Role> to string array of Role.Name
Hi,
The following work, but I'm pretty sure can be converted to a LINQ query, and been wasting time on it (Not necessary, but curiosity can be a killer sometimes)
(User got a member of type IList<Role> where Role have a member "RoleName")
Code:
public override string[] GetRolesForUser(string username)
{
var roles = new StringBuilder();
try
{
User user = UserRepository.GetUserByName(username, ApplicationName);
if (user != null)
{
foreach (Role role in user.Roles)
{
roles.Append(role.RoleName + ",");
}
}
}
catch (Exception ex)
{
throw new MemberAccessException("Error processing role data - " + ex.Message);
}
if (roles.Length > 0)
{
roles.Remove(roles.Length - 1, 1);
return roles.ToString().Split(',');
}
return new string[0];
}
Figured where I loop over the roles a query can do the job......no?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|