标签:
1.配置类
internal sealed class Configuration<TContext> : DbMigrationsConfiguration<TContext> where TContext : DbContext
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(TContext context)
{
}
}
2.初始化类
public class SchoolContext : DbContext
{
public SchoolContext() : base("name=test")
{
}
static SchoolContext()
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<SchoolContext, Configuration<SchoolContext>>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
}
}
3.实体类
public class Course { public int StudentID { get; set; } public string Name { get; set; } }
好。搞定。就这么简单。我也研究了半天,看了很多资料。就可以修改实体类看看数据库的变法吧。
标签:
原文地址:http://www.cnblogs.com/Logan626/p/5644472.html