我正在開發一個ASP.NET MVC Web應用程序,首先使用代碼和實體框架。ASP.NET MVC代碼首先用重命名的數據庫表遷移數據
我面臨的問題是,我使用數據遷移對幾個表進行了重命名,顯然一切正常,我甚至可以看到數據庫中更新的表名。
但是,當我創建一個新的數據遷移總是需要表(xxxxes)原來的名字,而不是最新(xxxxs),我必須手動更改遷移腳本,以避免錯誤:
Cannot find the object "dbo.xxxxs" because it does not exist or you do not have permissions.
而且更糟糕的是,該指數現在控制器失敗,因爲當它試圖它拋出以下錯誤ToList()方法:
An exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code Additional information: An error occurred while executing the command definition. See the inner exception for details.
作爲內部細節:
{"Invalid object name 'dbo.xxxxs'."}
我已經查看了整個項目,試圖找到這個表仍然以原始名稱引用的位置,但是我什麼也沒找到。
有關如何解決這個問題的任何想法?
編輯
我做了什麼,也許這裏就是一切爆發是創建這樣的數據遷移和運行它。
public partial class Update5 : DbMigration
{
public override void Up()
{
RenameTable("xxxxes", "xxxxs");
}
public override void Down()
{
}
}
我已經看到了向下()方法應該具有正好相反的動作,這是我沒有加...
所以你只是把名字從'model'+'es'改爲'model'+'s'?可能與[pluralization]有關(https://edspencer.me.uk/2012/03/13/entity-framework-plural-and-singular-table-names/)。 –
@SteveGreene我已更新我的問題,更多詳細信息... –