Andre Silveira

Andre Silveira

  • 1.6k
  • 155
  • 15.8k

Using EF.Functions Collate and a equivalent to SQL Server "Replace"

May 23 2023 11:34 PM

I have a Entity "produtos", a entity "index". The entity "produtos" has a list of "index", wich are keywords related to that product for search. It's a many to many relationship. I'm using the bellow code to make the search and it works, but I need to implement a equivalent of the SQL Server "Replace" function so that the query ignores a specific character ("-") in the search and returs records with or without them. For example if I search for TRex it will return TRex and T-Rex, and if I search T-Rex too.

I'm using this code and it's working, but I need to implement the "-" ignoring thing...

        var searchTerms = searchTerm.Split(' ');
                foreach (var term in searchTerms)
                {
                    if (term.Length > 1 && term !="de")
                    {                     
                        produtos = produtos.Where(p => p.Indice.Any(ind => EF.Functions.Collate(ind.PalavraChave, "Latin1_General_CI_AI") == term));
                    }
                }

 


Answers (2)