How to disable conventions in Microsoft.EntityFrameworkCore?

c# entity-framework-core sqlite

Question

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]
        }
1
9
4/20/2017 6:22:58 PM

Popular Answer

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();
}
0
6/24/2019 9:53:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow