The easiest way will probably look like this:
private static int MapPriority(string priority) { switch(priority.ToUpperInvariant())//skip the case bit if safe { case "HIGH": return 1; case "MEDIUM": return 2; case "LOW": return 3; default: return 4; } } var sorted = someCollection.OrderBy(i => MapPriority(i.PriorityProperty));
With the form supported by db, you will need a function in the database that you can call. It is only in memory.
With a lot of possible meanings, I would base it on a dictionary, not a manual code. I would make a manual codeword for three, as in this case, though (unless the values used can change, a further complication makes the dictionary-based approach the only way).
If you sort a large number of such elements or call them many, I would go with the implementation of IComparer<T> or the element itself would implement IComparable<T> .
source share