I'm having a problem with my orderby linq expression. It generates the output in a wrong order. I'm from Denmark and creating a danish website, therefor the order has to be exact ofc.
Here is my query:
var model = (from w in db.News
orderby w.Title
select w).ToList();
The output is:
1, 123
2, æøå
3, hallo
4, know
The correct order should be like this:
1, 123
2, hallo
3, know
4, æøå
How do I correct this?
You can pass string comparer to OrderBy
method if you will use fluent Linq syntax:
var model = db.News.OrderBy(w => w.Title, StringComparer.InvariantCulture)
.ToList();
BTW you can create string comparer specific to your culture with StringComparer.Create
method:
StringComparer.Create(new CultureInfo("da-DK"), true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With