繁体   English   中英

使用Entity Framework代码优先迁移来更改数据库表名称

[英]Change a database table name using Entity Framework code first migrations

您将如何使用Entity Frameworks代码优先迁移来更改表的名称。

以下代码将我的表创建为:

RoleBindingModel,DivisionBindingModel等,这并不理想。

您如何将名称更改为自定义表格名称? (无需更改型号名称)

IdentityModels.cs

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public DbSet<RoleBindingModel> Role { get; set; }
        public DbSet<DivisionBindingModel> Division { get; set; }
        public DbSet<CategoryBindingModel> Category { get; set; }
        public DbSet<ProductBindingModel> Product { get; set; }


        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

表名

一种方法是使用DataAnnotations和Table属性。

using System.ComponentModel.DataAnnotations.Schema;    

[Table("Role")]
public class RoleBindingModel
{

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM