[英]Add column to table in C# & Entity Framework code-first without deleting DB content
I have a database with several tables in AZURE SQL Server.我在 AZURE SQL Server 中有一个包含多个表的数据库。
I want to add a new column to one of the tables, but I want to keep all the content of the tables including the table with the new column;我想在其中一个表中添加一个新列,但我想保留表的所有内容,包括带有新列的表; hence I don't want to use the
因此我不想使用
Database.SetInitializer<MyDbContext>(new DropCreateDatabaseIfModelChanges<MyDbContext>());
My code looks like this:我的代码如下所示:
public class DBTables : DbContext
{
public DBTables() : base(ProductKeys.GetDbKey())
{
}
public DbSet<ElementsForPointTable> ElementsForPointTable { get; set; }
public DbSet<StationsDetailsTable> StationsDetailsTable { get; set; }
}
How do I do it?我该怎么做?
You could use migrations to update the database scheme.您可以使用迁移来更新数据库方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.