I'm using ASP.NET MVC 1 and I have added a custom Profile class using the WebProfile Builder VS add-in (found here: http://code.msdn.microsoft.com/WebProfileBuilder/Release/ProjectReleases.aspx?ReleaseId=980).
On one of my forms I want a drop-down list of all users who share a specific profile value in common.
I can see that I can get a list of all users using:
Membership.GetAllUsers()
However I cannot see how to get all users who have a specific profile value, which in my case is CellId.
Am I approaching this in the right way? I have used membership roles to define which users are administrators 开发者_StackOverflow中文版etc, but profiles seems like the right place to group users.
Any pointers both in specifics of how to access the user list but also comments on whether am I pursuing the right avenue here would be greatly appreciated.
Many thanks, Sam
There is no query API for Profile, but this may give you some guidance:
var usersWithNonZeroCounter = Membership.GetAllUsers().Cast<MembershipUser>()
.Where(user => true /*insert your user criteria here*/)
.Select(user => ProfileBase.Create(user.UserName, true))
.Where(profile => ((int)profile["counter"]) > 0 /*insert your profile criteria here*/)
.ToList();
If you only need one comparison you can use following statement:
return Membership.GetAllUsers().Cast<MembershipUser>()
.Where(user => ((int)ProfileBase.Create(user.UserName, true)["Owner"]) == _ownerid);
If you need more evaluations, why dont you use the let operator to store the profile in.
精彩评论