views:

411

answers:

3

Hello, Is it possible to sort a MembershipUserCollection by IsApproved and then Comment without modifying the Stored Procedure? Can Linq do this?

Thanks!

+1  A: 

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

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

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

users = users.OrderByDescending(x => x.IsApproved).ThenBy(x => x.Comment).ToList();
Mike C.
A: 

Not directly--the MembershipUsersCollection isn't linq friendly. You can, however, pretty easily make it Linq friendly as Mike C. points out--just new up a List<MembershipUser> with your users.

Wyatt Barnett
A: 

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

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