4

I have created a connectionstring in mvc3 application and it is working fine in mvc views and controllers and I am able to fetch data. Now I have called the repository/model functions in a Unit Test in Test project and I am getting error:

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

How can i fix it?

DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

3 Answers3

6

That has nothing to do particularly with MVC. As it seems, when testing, you use ConnectionString on database that does not have 'dbo.tblProduct' table/view. Check the connetion string and database. You may need to debug tests

archil
  • 39,013
  • 7
  • 65
  • 82
2

Check your table may have different schema (other then dbo) change it to dbo using query below

look at this. How do I change db schema to dbo

Community
  • 1
  • 1
0

Its very strange for my case, as it is required to do mapping between model and tables, the name has to be the same. When I added 's' at the end of table's name, it works. I don't know if this part work of what LINQ does.

Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
Moe
  • 197
  • 6