I have below code
public class Model { public int Id { get; set; } public string OrderNumber { get; set; } } class Program { static void Main(string[] args) { var models = new List<Model> { new Model {Id = 4, OrderNumber = "BT-3964-1"}, new Model {Id = 2, OrderNumber = "BT3924"}, new Model {Id = 1, OrderNumber = "bt3810v2"}, new Model {Id = 5, OrderNumber = "BILL-TEST100"}, new Model {Id = 3, OrderNumber = "BT-4887-Test3-Create"} }; var reorderedModels = models.OrderBy(x => x.OrderNumber); Console.WriteLine("The sorted models are:"); foreach (var model in reorderedModels) { Console.WriteLine($"OrderNumber: {model.OrderNumber}, Id: {model.Id}"); } } }
In .NET Core 3.1 and 2.1, it gives below output
The sorted models are:OrderNumber: BILL-TEST100, Id: 5OrderNumber: bt3810v2, Id: 1OrderNumber: BT3924, Id: 2OrderNumber: BT-3964-1, Id: 4OrderNumber: BT-4887-Test3-Create, Id: 3
But on .NET 5.0, it gives below output
The sorted models are:OrderNumber: BILL-TEST100, Id: 5OrderNumber: BT-3964-1, Id: 4OrderNumber: BT-4887-Test3-Create, Id: 3OrderNumber: bt3810v2, Id: 1OrderNumber: BT3924, Id: 2
Why the breaking changes?
Additional Note: even using OrderBy(x => x.OrderNumber, StringComparer.InvariantCultureIgnoreCase)
, this issue still happens