I'm developing an ASP.NET MVC 4 application using VS 2010 and EF 4.3. It retrieves some data from an external database and all worked as expected until I tried to recompile it one day. After the compilation I receive the following EF error:
Invalid column name 'CreatedOn'.
No DB or code changes were made - I've simply added some indentations for readability. The previous application versions from TFS also throw the same exception.
I have no CreatedOn
property in my entities and no such field in the database and I don't need it and don't want it in any case.
What should be done to avoid this exception?
This is my custom DB context I use to access data:
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);
}
}
And this is the Label class
public class BaseEntity : IDataEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string ChangedBy { get; set; }
}
public class Label : BaseEntity
{
}
See Question&Answers more detail:os