ASP.NET MemberhipUserCollection sorting IsApproved, comment

Is it possible to sort the MemberhipUserCollection using IsApproved and then the comment without modifying the stored procedure? Can Linq do this?

+2


source to share


3 answers


I found another example that used the following code (I used a generic list instead of MemberhipUserCollection):

users = users.OrderByDescending(x => x.IsApproved).OrderBy(x => x.Comment).ToList();

      



EDIT: DOH! Need ThenBy () instead of the second OrderBy ():

users = users.OrderByDescending(x => x.IsApproved).ThenBy(x => x.Comment).ToList();

      

+4


source


There is also this option to make it LINQ friendly before ordering.



IEnumerable<MembershipUser> members = sys.Membership.FindUsersByEmail(email).Cast<MembershipUser>();

      

+2


source


The members of MembershipUsersCollection itself are not linq friendly. However, you can easily make it Linq friendly, as Mike S. points out - just new List<MembershipUser>

with your users.

0


source







All Articles