Skip to content

OrderBy with non-english letters give different ordering result on string vs key selector #363

@perason

Description

@perason

The issue I have is that when using a string ("ProductId") for ordering it doesn't sort properly, e.g.

    CultureInfo culture = new CultureInfo("nb-NO");

    itemList = itemList.AsQueryable()
        .OrderBy("ProductId", StringComparer.Create(culture, true))
        .ToList();
Output:
Ååå
Ååå
Aaa
Aaa
Bbb
Bbb

but when using a key selector (s => s.ProductId) it does, e.g.

    CultureInfo culture = new CultureInfo("nb-NO");

    itemList = itemList.AsQueryable()
        .OrderBy(s => s.ProductId, StringComparer.Create(culture, true))
        .ToList();
Output:
Aaa
Aaa
Bbb
Bbb
Ååå
Ååå

I am using System.Linq.Dynamic.Core ver. 1.0.23.

I also tried with StringComparer.InvariantCulture, but its result is the same.

My itemList object(s) looks like this, and is a List<Inventory>

    public class MyModels
    {
        public int Id { get; set; }
        public DateTime CreateDate { get; set; }
        public DateTime EditDate { get; set; }
    }

    public class Inventory : MyModels
    {
        public string ProductId { get; set; }
        public string Name { get; set; }
        public string Price { get; set; }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions