2016-07-15 7 views
0

私は、この巧妙な機能に出くわした:How to Add Table Prefix In Entity Framework Code First Globally?EF6のプレフィックスと複数のテーブル名?

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     //prefix "PE" on table name 
     modelBuilder.Types().Configure(entity => entity.ToTable("PE" + entity.ClrType.Name)); 
    } 

しかし、これは私が欲しいpluralisationの機能を失います。 "s"を追加することはできません。なぜなら、 "puppy"のような型名は "puppies"ではなく "puppies"に複数化する必要があるからです。

答えて

0

あなたが根底にあるEF規則が使用される複数形のサービスを呼び出すことができます。

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
    //prefix "PE" on table name 
    var pluralizationService = DbConfiguration.DependencyResolver.GetService<System.Data.Entity.Infrastructure.Pluralization.IPluralizationService>(); 
    modelBuilder.Types().Configure(entity => entity.ToTable("PE" + pluralizationService.Pluralize(entity.ClrType.Name))); 
} 

そしてusing System.Data.Entity.Infrastructure.DependencyResolution;

を追加することを忘れないでくださいを
関連する問題