Remove seat seats on the database side with Asp.net core Entity Framework

Asked

Viewed 47 times

0

I have a method that I receive a string, does the search and returns all the data that is equal to the word I passed, like this:

        public async Task<List<ProductDto>> GetAllAsync(string name)
        {
            IEnumerable<Product> lstProducts = new List<Product>();

            lstProducts = await _productRepository.GetAsync(c => c.Name.StartsWith(name));

            return ProductMapper.Mapper.Map<List<ProductDto>>(lstProducts);
        }

I have a function that removes accents Utils.RemoveAccent(string palavra) I can perfectly remove from the parameter name exemplified above, the problem is that in the bank the word is with accent, for example I passed as search the Portuguese word and in the bank has a record as Portugese, as I can use this method I did, inside my lambda above?

ps: I tried something like:

stProducts = await _productRepository.GetAsync(c => Utils.RemoveAccent(c.Name).StartsWith(name));

But it didn’t work.

  • create a getter in property Name in your DTO that returns the name without accent would not solve?

  • i have to remove the accent only from the return of the search, however return for the user still has to go with accent, do not know if he managed to understand rsrs

  • ah got it, and you’re using Linqtoentities so what you tried really won’t work because it doesn’t know how to convert its function to an SQL. well, as suggestion you can use a customized SQL (you can do with EF or if you prefer with Dapper)

  • Face depends on the database you use, in Sqlserver has function for text search, in Oracle you need to create an index with function to do this search. If it’s Sqlserver take a look at the query with freetext and contains, depending on what you want one of the two to watch out for. But so, search for text in relational database is always a bitch, sometimes it pays more you use an indexer type Elastic or a non-relational database like Ravendb and Mongo for this

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.