Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable conventions in Microsoft.EntityFrameworkCore?

I'm using SQLite with EFCore, but I got a problem... how can I disable Conventions like Pluralize? Is it possible?

My ModelBuilder has not a property Conventions...

protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
             modelBuilder. [NOT HAS PROPERTY CONVENTION]
        }
like image 986
Rafael Avatar asked Feb 15 '26 15:02

Rafael


1 Answers

You can disable pluralizing naming convention as shown below.

public static class ModelBuilderExtensions
{
    public static ModelBuilder RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder)
    {
        foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
        {
            if (entityType.ClrType == null)
                continue;

            entityType.Relational().TableName = entityType.ClrType.Name;
        }

        return modelBuilder;
    }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.RemovePluralizingTableNameConvention();
}
like image 197
Mustafa Gursel Avatar answered Feb 17 '26 03:02

Mustafa Gursel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!