我已经看到其他答案,但我无法使其工作。我有一个简单,干净的网站有两种型号:支持上下文的模型已更改
博客型号:
Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations
Public Class Blog
Public Property BlogId() As Integer
Public Property Name() As String
Public Property Description() As String
Public Property DateCreated As Date
Public Overridable Property Articles() As ICollection(Of Article)
End Class
Public Class BlogDbContext
Inherits DbContext
Public Property Blogs As DbSet(Of Blog)
End Class
文章型号:
Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations
Imports GemcoBlog
Public Class Article
Public Property ArticleId() As Integer
Public Property BlogId() As Integer
Public Property Title() As String
Public Property Body() As String
Public Property DateCreated As Date
Public Overridable Property Blog() As Blog
End Class
Public Class ArticleDbContext
Inherits DbContext
Public Property Articles As DbSet(Of Article)
Public Property Blogs As DbSet(Of Blog)
End Class
当我添加它创建控制器和视图控制器,然后运行,我得到这个错误:
The model backing the 'ArticleDbContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
Source Error:
Line 12: Line 13: Function Index() As ViewResult Line 14:
Dim articles = db.Articles.Include(Function(a) a.Blog) Line 15:
Return View(articles.ToList()) Line 16: End FunctionSource File: C:\Users\darchual\documents\visual studio 2010\Projects\Blog\Blog\Controllers\ArticleController.vb
Line: 14
我该如何解决这个错误?
编辑:
我从数据库中删除的EdmMetaData表解决了这个。我需要这张桌子吗?对任何事物都有好处吗?
谢谢。
错误消息似乎暗示了您2种可能的解决方法。当你尝试他们时发生了什么? – 2012-07-26 14:15:36
感谢您的快速响应。我编辑了这个问题:“我通过从数据库中删除EdmMetaData表来解决这个问题,我需要这张表吗?它对任何事情都有好处吗?” – user1477388 2012-07-26 14:24:08
EdmMetaData被实体框架用来验证当前模型是否与数据库匹配。删除它使得EF认为一切都是最新的,所以它将无法检测到未来的变化。 – 2012-07-26 22:09:00