Entity Framework Core RC2 table name pluralization

前端 未结 7 2296
谎友^
谎友^ 2020-12-05 01:50

Is there a way to do what this code did in EF Core RC 2?

protected override void OnModelCreating(ModelBuilder modelBuilder)
{    
    modelBuilder.Convention         


        
7条回答
  •  天命终不由人
    2020-12-05 02:18

    In Entity Framework NET core v2 you can choose to pluralize or singularize DbSets and Collections with a hook.

    public class MyDesignTimeServices : IDesignTimeServices
    {
        public void ConfigureDesignTimeServices(IServiceCollection services)
        {
            services.AddSingleton();
        }
    }
    
    public class MyPluralizer : IPluralizer
    {
        public string Pluralize(string name)
        {
            return Inflector.Inflector.Pluralize(name) ?? name;
        }
    
        public string Singularize(string name)
        {
            return Inflector.Inflector.Singularize(name) ?? name;
        }
    }
    

    See this answer for more information: https://stackoverflow.com/a/47410837/869033

提交回复
热议问题