@ -44,7 +44,7 @@ public class MyProjectNameDbContext :
}
```
Since, ABP Framework merges all DbContext classes in the dependent modules of the final application, you should configure the `AbpDbContextOptions` in the module class of the `*.EntityFrameworkCore` project as follows:
In addition to that, you should configure the `AbpDbContextOptions` in the module class of the `*.EntityFrameworkCore` project to also apply this change in the dependent ABP modules (also for your own modules) as follows:
```csharp
public class MyProjectEntityFrameworkCoreModule : AbpModule
@ -77,13 +77,13 @@ Since, ABP Framework merges all DbContext classes in the dependent modules of th
}
```
After, you make these changes, you can create a new migration and apply it to your database. When you do that, all of the text based fields type will be changed as `citext` datatype. Then, you can write case-insensitive queries in your application without worry.
After you make these changes, you can create a new migration and apply it to your database. When you do that, all of the types of text-based fields will be changed as `citext` datatype. Then, you can write case-insensitive queries in your application without worry.
## Using Collations
Collation is a set of rules that determine how text data is sorted and compared in a dataset. PostgreSQL provides different collation settings for various languages and cultures. These settings can determine how text data is compared and can be configured to ignore case differences.
To perform case-insensitive or accent-insensitive operations, you should choose one of the non-deterministic collations. For example, you can define a collation as follows (in your `*DbContext.cs` file):
To perform case-insensitive or accent-insensitive operations, you should choose one of the [non-deterministic collations](https://postgresql.verite.pro/blog/2019/10/14/nondeterministic-collations.html). For example, you can define a collation as follows (in your `*DbContext.cs` file):
After these configurations, you should create a migration and apply it to your database as always. However, this solution comes with some problems, for example, with using non-deterministic collations, it's not yet possible to use pattern matching operators such as `LIKE` on columns. This is a huge problem, because it makes it hard to use LINQ. For example, you can't use `.EndsWith` or `.StartsWith` methods, because they are translated to `LIKE` command on the SQL level.
After these configurations, you should create a migration and apply it to your database as always.
However, this solution comes with some problems, for example, by using non-deterministic collations, it's not yet possible to use pattern matching operators such as `LIKE` on columns. This is a huge problem, because it makes it hard to use LINQ. For example, you can't use `.EndsWith` or `.StartsWith` methods, because they are [translated to `LIKE` command on the SQL level](https://www.npgsql.org/efcore/mapping/translations.html).
## Conclusion
In PostgreSQL, you can perform case-insensitive searches by using the citext data type or by utilizing collation settings. To make a decision to pick one of these options, you can follow the following points:
* If the accent is not important for you and only thing you want to do, is making the postgresql queries as case-insensitive, using the `citext` data type option should be selected.
* If the accent is really important for you, and you don't use LINQ methods (such as `StartsWith` and `EndsWith` methods), you can use collations. Note that, with this approach, queries that defined in the dependent modules also must not use these LINQ methods. Therefore, this approach, is not suitable with ABP Framework. Because, some of the modules uses LINQ methods (some pattern matching operators).
* If the accent is not important for you and the only thing you want to do, is make the PostgreSQL queries case-insensitive, using the `citext` data type option should be selected
* If the accent is really important to you, and you don't use LINQ methods (such as `StartsWith` and `EndsWith` methods), you can use collations.
* Note that, with this approach, queries that are defined in the dependent modules also must not use these LINQ methods. Therefore, this approach is not suitable with the ABP Framework. Because some of the modules use LINQ methods (some pattern-matching operators).
Regardless of the method chosen, you can enable users to perform searches without worrying about case sensitivity. This is crucial for providing a user-friendly experience and making your database queries more flexible.