开发者

ASP.NET MembershipUserCollection sort by IsApproved, Comment

Is开发者_开发知识库 it possible to sort a MembershipUserCollection by IsApproved and then Comment without modifying the Stored Procedure? Can Linq do this?


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();


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜