2011-11-22 138 views

回答

22

如果您只有一個映射到未複用的表的實體,則可以刪除PluralizingTableNameConvention並手動配置實體的表名。

public class MyContext : DbContext 
{ 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     base.OnModelCreating(modelBuilder); 

     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 

     modelBuilder.Entity<Item>().ToTable("Items"); 
    } 
} 

,或者如果周圍

public class MyContext : DbContext 
{ 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     base.OnModelCreating(modelBuilder); 

     modelBuilder.Entity<Item>().ToTable("Item"); 
    } 
} 
+0

輝煌,感謝otherway。 –