我已經看到其他答案,但我無法使其工作。我有一個簡單,乾淨的網站有兩種型號:支持上下文的模型已更改
博客型號:
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