[英]Invalid object name using code first Entity Framework on database table
I am using Entity Framework code-first migrations. 我正在使用Entity Framework代码优先迁移。 And I created a migration to change the name of a table in my database:
我创建了一个迁移来更改数据库中表的名称:
public partial class ChangeNameOfCodePerformanceAnchorTable : DbMigration
{
public override void Up()
{
RenameTable(name: "dbo.Code_PerformanceAnchor", newName: "CodePerformanceAnchor");
}
public override void Down()
{
RenameTable(name: "dbo.CodePerformanceAnchors", newName: "Code_PerformanceAnchor");
}
}
Now, when I create the controller for that table.. on the Index action I have this: 现在,当我为该表创建控制器时。在Index动作中,我有以下内容:
public ActionResult Index()
{
return View(db.CodePerformanceAnchor.Include(c => c.CodePhase).ToList());
}
When I run the application to get to that specific index page, I get this error: 当我运行应用程序以转到该特定索引页时,出现此错误:
Invalid object name 'dbo.CodePerformanceAnchors'.
无效的对象名称“ dbo.CodePerformanceAnchors”。
Description: An unhandled exception occurred during the execution of the current web request.
描述:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.
请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.CodePerformanceAnchors'.
异常详细信息:System.Data.SqlClient.SqlException:无效的对象名称'dbo.CodePerformanceAnchors'。
The only thing in my application that is called CodePerformanceAnchors
is the controller. 在我的应用程序中,唯一称为
CodePerformanceAnchors
是控制器。 The model is CodePerformanceAnchor
. 该模型是
CodePerformanceAnchor
。
public virtual DbSet<CodePerformanceAnchor> CodePerformanceAnchor { get; set; }
Any help on resolving this error would be greatly appreciated. 解决此错误的任何帮助将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.