Change db table name in EF4 (entity framework 4)

后端 未结 6 2097
离开以前
离开以前 2020-12-01 18:53

Does anyone know how to change the mapped db table for an entity in EF4 (entity framework 4)?

Later edit: I think i\'ve found the place where the table names are def

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 19:08

    An alternative solution would be to override a method in your DbContext class.

    public class MyDbContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity().ToTable("DB_PRODUCTS_TBL");
            // otherwise EF assumes the table is called "Products"
        }
    }
    

提交回复
热议问题