Asp.net-Mvc
實體框架 4.3。列名“CreatedOn”無效
我正在使用 VS 2010 和 EF 4.3 開發一個 ASP.NET MVC 4 應用程序。它從外部數據庫中檢索一些數據,並按預期工作,直到有一天我嘗試重新編譯它。編譯後我收到以下 EF 錯誤:
列名“CreatedOn”無效。
沒有對數據庫或程式碼進行任何更改——我只是添加了一些縮進以提高可讀性。TFS 以前的應用程序版本也拋出相同的異常。
我的實體中沒有
CreatedOn屬性,數據庫中也沒有這樣的欄位,我不需要它,在任何情況下都不想要它。應該怎麼做才能避免這種異常?
這是我用來訪問數據的自定義數據庫上下文:
public class MyContext<T> : DbContext where T : class, IDataEntity { public MyContext(string connectionKey) : base("name=" + connectionKey) { Configuration.AutoDetectChangesEnabled = false; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Label>().Property(item => item.Id).HasColumnName("LabelId"); modelBuilder.Entity<Label>().Ignore(item => item.ChangedBy); } }這是標籤類
public class BaseEntity : IDataEntity { public int Id { get; set; } public string Name { get; set; } public string ChangedBy { get; set; } } public class Label : BaseEntity { }
就我而言,它是 MiniProfiler。我使用 EF 5.0,它使用 EF 4.x。禁用分析器後,不再拋出異常
EF 4.3.1 向表中添加了一
CreatedOn列__MigrationHistory,隨後 EF 5.0 將其刪除。我懷疑自上次更新數據庫以來您已將 EF 升級到 4.3.1。您可以執行遷移以添加
CreatedOn列,自行手動添加,或者升級到不再需要的 EF 5.0。