我正在使用我的代码优先方法在MVC4中制作项目。我需要更新我的模型带代码迁移的MVC更新模型
我有以下属性,它需要被更新,我怎么能做到这一点
public class ContactForm
{
public char Phone { get; set; }
}
public class ConContext : DbContext
{
public DbSet<ContactForm> ContactForms { get; set; }
}
}
我想更新手机属性格式来
public char Phone { get; set; }
日Thnx提前,我已经安装迁移到我谟已经
我configuration.cs
namespace MyCRM.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<MyCRM.Models.ConContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(MyCRM.Models.ConContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
哪部分不起作用?代码的更新,控制台上的迁移或部署到数据库? – 2014-09-23 14:17:19
当我在代码中简单更新时,我们必须始终删除我的数据库,这不是那么古德@SamuelCaillerie – 2014-09-23 14:18:59
当您运行“添加迁移”时,这会在您的解决方案中生成一个新的可更新的c#文件。它在你的案例中产生了什么:一列旧列并添加新列?您可以查看http://msdn.microsoft.com/en-us/data/jj591621.aspx#customizing以定制您的迁移。 – 2014-09-23 14:26:05