none
how can I get users with role admin ? RRS feed

  • Question

  • I use Microsoft aspnet tables. How can I get users with role 'admin' ? I think I need tabel aspnet_Users and aspnet_Roles ?

    from x in Db.DataContext.aspnet_Users
              where ??????????
              select x


    Friday, June 24, 2011 2:46 PM

Answers

  • Hi green_green;

    OK, the image had the navigation properties cut off so if this does not work change aspnet_Roles to match the navigation property for that table.

    var adminUsers = from u in Db.DataContext.aspnet_Users
             from r in u.aspnet_Roles
             where r.RoleName == "admin"
             select u;
    

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by green_green Friday, June 24, 2011 6:48 PM
    Friday, June 24, 2011 6:34 PM

All replies

  • Hi green_green;

    Try the query like this, I believe this should give you what you need.

    var adminUsers = from u in Db.DataContext.aspnet_Users
             where u.aspnet_Roles.RoleName == "admin"
             select u;
    


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 24, 2011 4:07 PM
  • I thought about that but I can use only  SourceRoleName or TargetRoleName - this is strange because in table I have RoleName, why ?
    Friday, June 24, 2011 4:39 PM
  • Hi green_green;

    To your question:

    I thought about that but I can use only SourceRoleName or TargetRoleName - this is strange because in table I have RoleName, why ?

     That is difficult to say without seeing the model. I based my query on this, http://msdn.microsoft.com/en-us/library/Aa478948.asp2prvdr0102l(l=en-us).gif, If you notice I don't see a SourceRoleName or TargetRoleName in this.

    Can you poat and image of yours?

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 24, 2011 5:00 PM
  • Friday, June 24, 2011 5:27 PM
  • Hi green_green;

    OK, the image had the navigation properties cut off so if this does not work change aspnet_Roles to match the navigation property for that table.

    var adminUsers = from u in Db.DataContext.aspnet_Users
             from r in u.aspnet_Roles
             where r.RoleName == "admin"
             select u;
    

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by green_green Friday, June 24, 2011 6:48 PM
    Friday, June 24, 2011 6:34 PM
  • thx man :)
    Friday, June 24, 2011 6:48 PM
  • Not a problem, glad to help.

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 24, 2011 6:53 PM