【发布时间】:2014-09-12 17:54:48
【问题描述】:
以下是我的数据库上下文,我已经覆盖了名为OnModelCreating 的方法以使用Fluent API。当我构建解决方案时,我没有收到任何错误,但架构也保持不变。
public class BreakAwayContext : DbContext
{
public BreakAwayContext()
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<BreakAwayContext>());
}
public DbSet<Destination> Destinations { get; set; }
public DbSet<Lodging> Lodgings { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Destination>().Property(d => d.Name).IsRequired();
modelBuilder.Entity<Destination>().Property(d => d.Description).HasMaxLength(600);
modelBuilder.Entity<Destination>().Property(d => d.Photo).HasColumnType("image");
modelBuilder.Entity<Lodging>().Property(l => l.Name).IsRequired().HasMaxLength(200);
}
}
这是一个屏幕截图,显示 Description 列的长度没有变化。
覆盖上述方法后是否需要Add-Migration 或Update-Database?
【问题讨论】:
-
添加模型创建后是否使用过db上下文?
-
如你所说,尝试更新数据库。
标签: c# asp.net asp.net-mvc entity-framework entity-framework-4