Hi,

I work on one project in ASP.NET MVC3. Everything worked fine, until I created new table Price_Ranges. I then tried to get data using LINQ, the following code:

IEnumerable<PriceRange> priceRanges = from pr in dbContext.PriceRanges
                                                    join cat in dbContext.Categories on pr.Category_Id equals cat.Id
                                                    where cat.Id==categoryId
                                                    select pr;

Then I use this IEnumerable in my view.
dbContext is EFDbContext class and everything is ok width it.

When I try to run this, it shows me exception:

System.Data.SqlClient.SqlException: Invalid object name 'dbo.PriceRanges'.

Is there anything I should do so asp.net recognize newly created tables in database?
How can I solve this problem.

Thanks in advance,

Amer

Recommended Answers

All 3 Replies

You have referred to the table as Price_Ranges and PriceRanges. Which one is correct? If it is Price_Ranges in the database then no, dbo.PriceRanges does not exist.

hi dude

i think there is no table in that db. plz refer proper db accessed
another thing is rename dbo.PriceRanges to PriceRanges

Hi,

Thanks for answers.
hericles was right. I made a mistake in naming my table in code. I forgot "_" letter. It usually happens after 9 hours of coding.

Thanks you very much again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.