Sorting with a specific collation!

Posts   
 
    
cfwettermark avatar
Posts: 7
Joined: 04-May-2005
# Posted on: 26-Sep-2005 12:40:42   

Hi y'all!

Could anyone point me in the right to direction how to go about in including a sql collation when sorting. Ideally, I would like to be able to provide a collation string when constructing my sort object. The reason: we have objects in multiple languages, and for instance the Swedish letter "å" is sorted before "a" if no collation is provided...

this is the kind of query I would like to create: select * from Place where CountryCode = 'SE' order by Name collate SQL_SwedishStd_Pref_Cp1_CI_AS

Any help on this would be appreciated!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Sep-2005 15:06:50   

One way to have the result you want, is to use the returned EntityCollection Sort Method, which have an overload that accepts System.Collections.IComparer.

And then you have 2 options either to implement this interface yourself, or use a class that implements it like "System.Collections.CaseInsensitiveComparer", which accepts "System.Globalization.CultureInfo" in it's constructor.

To illustrate this by an example:

CultureInfo myCultureInfo = new CultureInfo("sv-SE", false);

customers.SupportsSorting = true; customers.Sort((int)CustomerFieldIndex.CompanyName, ListSortDirection.Ascending, new CaseInsensitiveComparer(myCultureInfo));

I hope this one works fine with you.