abp icon indicating copy to clipboard operation
abp copied to clipboard

How to remove double quotes from the table and column names in the system when using pgSQL in abp vnext

Open netrain9111 opened this issue 2 years ago • 5 comments

How to remove double quotes from the table and column names in the system when using pgSQL in abp vnext. For example, if the system defaults to: select "TenantId" from "AbpUser", I would like the system to use : select tenant Id from abpuser . Because my database table and column names are created in lowercase

My system database was migrated from SQL SERVER, and after migration, it indicates that both the database and column names are lowercase without double quotes.

netrain9111 avatar Dec 17 '23 10:12 netrain9111

hi

My system database was migrated from SQL SERVER

You can delete all existing migration files and recreate new pgsql migrations.

maliming avatar Dec 18 '23 01:12 maliming

Hi From what I have seen, even if you recreate the migration you will still get double quotes in pgqsl. This is super annoying but Postgres is case sensitive (TenantId != tenantid). NpgSql will translate all camel case tables and fields to be double quoted.

Only solution if found is to snake case my own modules tables and fields but existing core abp module will fail at runtime if you force a lowercase or another naming convention because each module have their own dbContext which is unaware of the changes.

rlavaud avatar Dec 24 '23 13:12 rlavaud

hi

You found the wrong solution.

Please test your code in plain ef core project.

maliming avatar Dec 25 '23 00:12 maliming

@maliming reviving this issue since there are new overriding features for abpdbcontext. Do you mind posting a small howto on removing double quotes in postgres by overriding the name to snake case?

I have been trying to use these function but the Migration project is not working

options.DefaultConventionAction = (dbContext, builder) =>
{
    // This action is called for ConfigureConventions method of all DbContexts.
};

options.ConfigureConventions<YourDbContext>((dbContext, builder) =>
{
    // This action is called for ConfigureConventions method of specific DbContext.
});

options.DefaultOnModelCreatingAction = (dbContext, builder) =>
{
    // This action is called for OnModelCreating method of all DbContexts.
};

options.ConfigureOnModelCreating<YourDbContext>((dbContext, builder) =>
{
    // This action is called for OnModelCreating method of specific DbContext.
});

Can we use options.ConfigureOnModelCreating along with naming conventions to get this done?

rlavaud avatar Mar 02 '25 13:03 rlavaud

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 06 '25 03:05 stale[bot]