Entity Framework Code first 禁止重建資料表庫資料 和實體類修改後如何對應表

來源:互聯網
上載者:User

嘗試使用 Entity Framework Code first  寫好代碼後  資料庫自動產生   很簡單方便 。 現在問題來了  需求變化 需要增加欄位  甚至增加表

 

這時會報錯     增加欄位儲存出來的東西是 The model backing the 'BlogDB' 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.   增加表報錯的是 更新條目錯誤          原因是EdmMetadata  有個這個表  再檢查與實體是否匹配  只要把這個表刪了  然後手動增加欄位 讓欄位與實體匹配  就可以了 但不知道這樣會有什麼不好的影響沒~  希望知道的人說下 謝謝    還有 不知道有什麼別的方法嗎? 記得重寫

OnModelCreating來解決 希望知道人說下~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.