Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore accents on search using linq to entities (EF)

i need to perform a search on over a table whit a string field that contains accents (á, ì, ü, etc) im using EF 6

first i try i direct search like:

 var listaResultados = db_hms.Topology
                .Where( t => t.is_active == true && ((t.display_name.Contains(busqueda))||(t.detail.Contains(busqueda))))

but this is accent sensitive, then i try this:

t.display_name.IndexOf(busqueda, StringComparison.InvariantCultureIgnoreCase) >= 0

but is not supported on linq to Entities

any other idea please pd: i need to perform the search on a "Contains" way, not a starts whit.

like image 598
EricGS Avatar asked Jan 24 '26 17:01

EricGS


1 Answers

These comparisons will depend on collation you selected when creating your SQL Server Database. I don't know if the EF has any workarounds but you can possibly get around this using a stored procedure to invoke something along the lines of this:

How do I perform an accent insensitive compare (e with è, é, ê and ë) in SQL Server?

like image 113
andleer Avatar answered Jan 27 '26 10:01

andleer



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!