System.Data.EntityCommandExecutionException:执行时发生错误

问题描述:

我已经在mvc3应用程序中创建了一个连接字符串,它在mvc视图和控制器中工作正常,我能够获取数据。现在,我已经叫测试项目的单元测试库/模型的功能和我得到的错误:System.Data.EntityCommandExecutionException:执行时发生错误

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'. 

我怎样才能解决这个问题?

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

检查表可以有不同的模式(其他然后DBO)更改使用下面

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

对我而言,这很奇怪,因为它需要在模型和表格之间进行映射,名称必须相同。当我在表格名称末尾添加's'时,它会起作用。我不知道这部分是LINQ所做的工作。