我已经看到了其他答案,但我无法让它发挥作用。我有一个简单、干净的网站,有两个模型:
博客模型:
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
当我添加创建控制器和视图的控制器,然后运行时,我收到此错误:
自数据库创建以来,支持“ArticleDbContext”上下文的模型已更改。手动删除/更新数据库,或使用 IDatabaseInitializer 实例调用 Database.SetInitializer。例如,DropCreateDatabaseIfModelChanges 策略将自动删除并重新创建数据库,并可选择使用新数据为其播种。
源错误:
第 12 行:第 13 行:函数 Index() As ViewResult 第 14 行:
Dim article = db.Articles.Include(Function(a) a.Blog) 第 15 行:
返回 View(articles.ToList()) 第 16 行:结束函数源文件:C:\Users\darchual\documents\visual studio 2010\Projects\Blog\Blog\Controllers\ArticleController.vb
行:14
我该如何解决这个错误?
编辑:
我通过从数据库中删除 EdmMetaData 表来解决这个问题。我需要这张桌子吗?它对任何事情都有好处吗?
谢谢。