Linq 按国家字符集排序
我有一个列表,我按字母顺序对某个属性进行排序。
不幸的是,数据库设置(我猜)在获取数据时无法正确处理国家字符。但我无法更改这一点(不是我的数据库),所以我需要直接解决这个问题。因此我简化了下面的例子。
var x1 = new Shop() {city = "Århus"};
var x2 = new Shop() { city = "Ans" };
var x3 = new Shop() { city = "Balle" };
list.Add(x1);
list.Add(x2);
list.Add(x3);
list = list.OrderBy(a => a.city).ToList();
//Result:
// Århus, Ans, Balle
// Should be:
// Ans, Balle, Århus
注释应该解释我的问题:“Å”是丹麦语字符集中的最后一个字母
我无法控制应用程序设置,但我可以强制 OrderBy 使用特定字符集进行排序吗?
提前致谢,
斯蒂恩·佩德森
I have a List which i OrderBy alfabetically on a property.
Unfortunatly the database setup (i guess) does not handle national characters properly when fetching the data..I cannot change that though (not my database), so I need to solve the problem directly on this specific. I have therefore simplified the example below.
var x1 = new Shop() {city = "Århus"};
var x2 = new Shop() { city = "Ans" };
var x3 = new Shop() { city = "Balle" };
list.Add(x1);
list.Add(x2);
list.Add(x3);
list = list.OrderBy(a => a.city).ToList();
//Result:
// Århus, Ans, Balle
// Should be:
// Ans, Balle, Århus
The commentes should explain my problem: The "Å" is the last letter in danish character set
I am not in control over the application settings, but can I force the OrderBy to order using a specific caracter set?
Thanks in advance,
Steen Pedersen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在订购时指定文化。例如:
打印:
You could specify a culture when ordering. For example:
prints: