<p>I'm using membership and roles for authentication in my vb .net application. We have about 5 roles in the application with certain roles filling out a specific profile value. Example is the role is store and the profile value is store number. Obviously if you work for headquarters you don't have a store number so I don't care about it. Each store can also have more than 1 employee.</p>

<p>I need to get the users for a specific store number. Meaning I would only want the users that belong to store number 101 to show up that list. The way that we are doing this now is going through all the users and adding the users that fit the criteria into a sorted list. This functions but the problem is when you start passing about 3,000 users or so. It just becomes to slow to be any good. </p>

<p>How would you guys find a different way of doing it? I really don't want to do custom stored procedure or changing the underlying classes because I'm afraid of it all breaking on a later version of .net that they change membership and roles.</p>

[{'answer_id': 75970, 'author': 'Grank', 'author_id': 12975, 'author_profile': 'https://Stackoverflow.com/users/12975', 'pm_score': 0, 'selected': False, 'text': "<p>You're using the built-in .NET role manager that saves to a SQL Server instance I take it?  What format are your user object in when you're currently looking at them to evaluate the criteria?  If you post a code sample I have an idea...</p>\n"}, {'answer_id': 75984, 'author': 'Jon', 'author_id': 12261, 'author_profile': 'https://Stackoverflow.com/users/12261', 'pm_score': 1, 'selected': False, 'text': "<p>This is really the sort of thing you want to filter on in SQL. I don't think there is any trick to get around doing a linear scan of your data and get the results you want.</p>\n\n<p>If doing this in SQL isn't an option then maybe you can avoid creating a second list and just sort your main user array and have the display only display the ones you care about. That would save the memory copy time at least.</p>\n"}, {'answer_id': 76517, 'author': 'Alfonso Pajares', 'author_id': 12369, 'author_profile': 'https://Stackoverflow.com/users/12369', 'pm_score': 0, 'selected': False, 'text': '<pre><code>    Public Shared Function LoadALLUsersInRole(ByVal Code As Integer, ByVal Role As String) As ArrayList\n        Dim pb As ProfileBase\n        Dim usersArrayList As New ArrayList\n        Dim i As Integer\n        Dim AllUsersInRole() As String = Roles.GetUsersInRole(Role)\n\n        For i = 0 To AllUsersInRole.Length - 1\n\n            pb = ProfileBase.Create(AllUsersInRole(i), True)\n\n            \'Check to see if the current user in the collect belongs to this Store.\n            If CType(pb.GetPropertyValue("Store.Code"), Integer) = Code Then                    \n                    usersArrayList.Add(AllUsersInRole(i))                   \n            End If\n            pb = Nothing\n        Next\n\n        Return usersArrayList\n    End Function\n</code></pre>\n\n<p>That is the example code of how I\'m doing it. The reason that I don\'t want to do it on the SOL side is that I would have a huge dependency on the fact that membership and roles doesn\'t change.</p>\n'}]
['https://Stackoverflow.com/questions/75712', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12369/']