【问题标题】:System.Data.EntityCommandExecutionException: An error occurred while executing thSystem.Data.EntityCommandExecutionException:执行时出错
【发布时间】:2011-08-01 12:27:47
【问题描述】:

我在 mvc3 应用程序中创建了一个连接字符串,它在 mvc 视图和控制器中工作正常,我能够获取数据。现在我在测试项目中的单元测试中调用了存储库/模型函数,但出现错误:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid object name 'dbo.tblProduct'.

我该如何解决?

【问题讨论】:

    标签: asp.net asp.net-mvc-3


    【解决方案1】:

    这与 MVC 无关。看起来,在测试时,您在没有“dbo.tblProduct”表/视图的数据库上使用 ConnectionString。检查连接字符串和数据库。您可能需要调试测试

    【讨论】:

      【解决方案2】:

      检查您的表可能有不同的架构(除了 dbo)使用下面的查询将其更改为 dbo

      看看这个。 How do I change db schema to dbo

      【讨论】:

        【解决方案3】:

        这对我来说很奇怪,因为需要在模型和表之间进行映射,名称必须相同。当我在表名的末尾添加“s”时,它可以工作。我不知道这部分是否适用于 LINQ。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-05-13
          • 2012-02-25
          • 2018-08-05
          • 2015-01-01
          • 2019-01-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多