Is it posible to do a select for postgresql using UNACCENT extension IN EF CORE 3.1 with npgsql?
Asked Answered
E

1

6

I have read about this for in Npgsql and Entity Framework Query PostgreSQL with Npgsql and Entity Framework using unaccent, BUT Entity Framework CORE.

Is it posible to do a select for postgresql using unaccent extension USING EF CORE 3.1?

How to translate, as example,

select * from users where unaccent(name) = unaccent('João')

to a .net core 3.1 using EF core and npgsql

thanks

Ealing answered 6/4, 2020 at 10:16 Comment(0)
I
1

The solution is here: Query PostgreSQL with Npgsql and Entity Framework using unaccent

First register the extension:

protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasPostgresExtension("unaccent");
            ...
        }

Then you can use the extension using EF.Functions.Unaccent:

.Where(x => people.ILike(EF.Functions.Unaccent(x.Name)....
Inaction answered 4/9, 2023 at 10:51 Comment(1)
A far better solution would be to use an accent-insensitive column collation. Applying functions to fields prevents the database from using indexes. Unless you also create an index based on the function expressionRosyrot

© 2022 - 2024 — McMap. All rights reserved.