我正在开发使用VS 2010和EF 4.3的ASP.NET MVC 4应用程序。它从外部数据库中检索一些数据,并按预期工作,直到有一天我尝试重新编译它为止。编译后,我收到以下错误EF:实体框架4.3。无效的列名'CreatedOn'
Invalid column name 'CreatedOn'.
没有DB或代码进行了更改, - 我只是增加了可读性一些缺口。以前的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);
}
}
这是Label类
public class BaseEntity : IDataEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string ChangedBy { get; set; }
}
public class Label : BaseEntity
{
}
您可以发布'Label'类吗? – Eranga
这是标签类别: public class BaseEntity:IDataEntity { public int Id {get;组; } public string Name {get;组; } 公共字符串ChangedBy {get;组; }} 公共类标签:BaseEntity {} – msaruyev
这个问题也是在这里讨论: http://stackoverflow.com/questions/19646659/createdon-column-in-entity-framework-6 – AXMIM