Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 495
Ashkan Mobayen Khiabani Avatar asked Aug 28 '26 23:08

Ashkan Mobayen Khiabani


1 Answers

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"));
like image 100
Mielipuoli Avatar answered Aug 30 '26 12:08

Mielipuoli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!