Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
614 views
Welcome To Ask or Share your Answers For Others

1 Answer

In my case it was the MiniProfiler. I use EF 5.0, it uses EF 4.x. After disabling the profiler, the exception was not thrown any more


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...