0

I'm using an Enum property called flags with EF5. One of these flags is a 'sticky' flag. I have a list of items which I want to order by date, but I want all the stickies at the top. Is there any way to retrieve all stickies first, ordered by date, then all the rest, ordered by date?

My enum declaration is:

[Flags]
public enum ForumTopicFlags : int
{
    None = 0,
    Sticky = 1,
    Spam = 2,
    Deleted = 4,
    Locked = 8
}
4

1 回答 1

1

Quite simple, really:

var result = myList
     .OrderByDescending(x => (x.Flags & ForumTopicFlags.Sticky) != 0)
     .ThenBy(x => x.Date);
于 2013-08-08T09:10:17.157 回答