1.??The model backing the ‘MusicStoreDBContext‘ context has changed since the database was created.?
Consider using Code First Migrations to update the database
?
?
Movie這個表是用來記錄Model的版本號的,你每次重新生成一次數據庫它就會重新給ModelHash列賦一個新值。
和原始數據庫就會產生差異.
2. 自動將數據庫的表名變復數,導致錯誤
?
方法一:使用TableAttribute為實體類指定映射的表名
1 [Table("User")] 2 public class User 3 { 4 [Key] 5 public int Id { get; set; } 6 public string Usn { get; set; } 7 public string Pwd { get; set; } 8 public DateTime Created { get; set; } 9 }
方法二:重寫OnModelCreating方法不允許將表名變為復數形式
public class UserContext : DbContext {public UserContext(): base("Name=SQLServer"){ }protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();}public DbSet<User> User { get; set; } }
重要::Movie這個表是用來記錄Model的版本號的,你每次重新生成一次數據庫它就會重新給ModelHash列賦一個新值。
和原始數據庫就會產生差異.
解決方法 :
Global.asax??里添加 Database.SetInitializer<_001.Models.MovieDBContext>(null);
??protected void Application_Start()
????????{
????????????Database.SetInitializer<_001.Models.MovieDBContext>(null);