简体   繁体   中英

Why do I get error Invalid Object Name 'dbo.OrderItemSubType' ('System.Data.SqlClient.SqlException)?

This one is killing me. I get the above error in the following line of code:

return (from orderItemSubTypes in dbOrders.OrderItemSubTypes
select new OrderItemSubType
{
    OrderItemSubTypeID = orderItemSubTypes.OrderItemSubTypeID,
    Name = orderItemSubTypes.OrderItemSubType
}).ToList<OrderItemSubType>();

This is from a WPF application which runs fine. I came across the error when trying to set up a context for my unit tests ie it appears in Nunit. I have created a console app and added my WPF app as a reference. This also gives the same error. dbOrders does contain a table called OrderItemSubType according to intellisense. Also, this is the third call to the database in the setting up sequence. The other calls are on other tables and work with no problem. I have tried removing and re-adding the table via the designer and also deleting the table from the database and re-adding it. I have also tried a different name for the table. Why would the query work fine in the WPF app but not when called from another project with the wpf app added as a reference? I am using VS2013 and SQLServerExpress 10.50. and Nunit for my unit tests. I'm not using Entity Framework or anything else. I'm simply creating tables using the SQL Server Object Explorer and then adding the tables to the .dbml file using the designer. The whole development is standalone on a single PC.

I've tried to look for a solution but the problem is the generic nature of the error that comes back.

Thanks in advance for any help.

You probably found your answer 2 years ago, but if anyone finds this later:

I had a similar issue and solved it by hitting the separate database.publish.xml I have in my SQL Project for tests . (I thought I had hot both the main DB and integration test DB publish scripts, but I guess I hadn't).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM