Q:

How to sort case insensitive with System.Dynamic.Linq?

I use System.Linq.Dynamic to order an items list.
items = items.AsQueryable().OrderBy("Name ASC");

To my surprise, lowercase names gets ordered after the capital cased names, so the items are returned something like this.
Ape
Cat
Dog
alligator
ant
beetle

I expected this order:
alligator
ant
Ape
beetle
Cat
Dog

Is there a way to get the correct order? Checked all method signatures for OrderBy and googled around, but nada.

A:

You do not need to create a custom comparer because there's already a StringComparer class which derives from IComparer.
words.OrderBy (x => x, StringComparer.OrdinalIgnoreCase)

This way, you do not need to create different IComparer implementations if you wanted to use other string comparison methods, like StringComparer.InvariantCultureIgnoreCase.
However, this might be desirable depending on your situation. For example, I do have multiple extension methods defined in LINQPad, like OrderBySelfInvariantCultureIgnoreCase, because it is convenient to use this with code completion rather than typing out the equivalent code by hand:
public static IEnumerable<string> OrderBySelfInvariantCultureIgnoreCase(this IEnumerable<string> source)
{   
    return source.OrderBy (x => x, StringComparer.InvariantCultureIgnoreCase);
}

A:

You must create a custom comparer, such as:
public void Main() 
{   
    String[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" }; 

    var sortedWords = words.OrderBy(a => a, new CaseInsensitiveComparer()); 

    ObjectDumper.Write(sortedWords); 
} 

public class CaseInsensitiveComparer : IComparer<string> 
{ 
    public int Compare(string x, string y) 
    { 
        return string.Compare(x, y, StringComparison.OrdinalIgnoreCase); 
    } 
}

Found @ https://code.msdn.microsoft.com/SQL-Ordering-Operators-050af19e

