Entity Framework 4.3. Invalid column name 'CreatedOn'

前端 未结 4 2012
盖世英雄少女心
盖世英雄少女心 2020-12-17 10:31

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

相关标签:
4条回答
  • 2020-12-17 11:02

    Found an answer for my question. Thanks all for replies.

    Database.SetInitializer<MyContext<Label>>(null);
    

    This fixes the problem and disables DB changes tracking in EF.

    0 讨论(0)
  • 2020-12-17 11:02

    Actually there is CreatedOn column in __MigrationHistory table so the problem might be something EF migrations related. If there are no codechanges,pending migrations or anything the error is indeed a very strange case.

    PS. I found this, it might prove helpful: http://bstechnical.blogspot.fi/2012/08/invalid-column-name-createdon-code-first.html

    0 讨论(0)
  • 2020-12-17 11:03

    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

    0 讨论(0)
  • 2020-12-17 11:12

    EF 4.3.1 added a CreatedOn column to the __MigrationHistory table, which EF 5.0 subsequently removed. I suspect you have upgraded EF to 4.3.1 since you last updated the database.

    You could either run a Migration to add the CreatedOn column, manually add it yourself, or upgrade to EF 5.0 where it is no longer necessary.

    0 讨论(0)
提交回复
热议问题