Search code examples
c#sql-serverlinqlinq-to-sql

Using collation in Linq to Sql


Imagine this sql query

select * from products order by name collate Persian_100_CI_AI asc

Now using Linq:

product = DB.Products.OrderBy(p => p.name); // what should I do here?

How can I apply collation?


Solution

  • This is now possible with EF Core 5.0 using the collate function.

    In your example the code would be:

    product = DB.Products.OrderBy(p => EF.Functions.Collate(p.name, "Persian_100_CI_AI"));