Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

asp.net mvc - Entity Framework 4.3. Invalid column name 'CreatedOn'

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...