码迷,mamicode.com
首页 > 其他好文 > 详细

修改model,映射到表中

时间:2017-11-19 20:55:20      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:实现   div   ble   auto   col   ase   映射   prot   config   

1.实现方法:

public class MyContext : DbContext
{
    public MyContext()
        : base("name=MyContext")
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext,MyConfiguration>()); //重要
    }

    public virtual DbSet<Student> Students { get; set; }
    public virtual DbSet<Course> Courses { get; set; }
}
internal sealed class MyConfiguration : DbMigrationsConfiguration<MyContext>
{
    public MyConfiguration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;
    }

    protected override void Seed(MyContext context)
    {

    }
}

 

修改model,映射到表中

标签:实现   div   ble   auto   col   ase   映射   prot   config   

原文地址:http://www.cnblogs.com/zhuxiang1633/p/7861166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!