LINQ orderby在瑞典文化中不起作用

时间:2018-10-23 12:19:16

标签: linq

如何基于CurrentUICulture设置LINQ排序

  var actorQuery = (from actor in actorList
                              where !actor.IsLocked
                              select new { Id = actor.Id, Name = string.Format("{0} {1}", actor.Name, actor.BusinessId) }).OrderBy(actor => actor.Name);

1 个答案:

答案 0 :(得分:0)

订单由CurrentCulture而非CurrentUICulture确定 示例:

var a = new string[] {"å","ä","ö","a","b","c"};
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
a.OrderBy(x => x).Dump(); //a,b,c,å,ä,ö

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
a.OrderBy(x => x).Dump(); //a,ä,å,b,c,ö

因此,只需在设置CurrentCulture的同时设置CurrentUICulture