1

I have an ASP.NET MVC web app using Entity Framework. After deploying I decided to rename a column for consistency reasons. I fixed it in the EF model and the local database that the model is based on. Since publish to filesystem can't update the database, I fixed it by hand in the SQL Server Express database on the destination server.

But the web app gets an error saying "Invalid column name 'LastUpdateTime'." (which is what I renamed it to). I can see in SQL Server Express that the column is there and that is how it's spelled.

I copied the query from the web app log and ran it directly against the database. It worked but I was getting the red squiggly lines under LasUpdateTime. I found this stackexchange article sql server invalid object name - but tables are listed in SSMS tables list, and following the answer there, the red squiggly lines went away, but the web app still gets the error.

Here's the query as EF created it.

SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[Name] AS [Name], 
    [Extent1].[Description] AS [Description], 
    [Extent1].[IsPrivate] AS [IsPrivate], 
    [Extent1].[LastUpdateTime] AS [LastUpdateTime], 
    [Extent1].[ThumbnailPhoto_Id] AS [ThumbnailPhoto_Id]
    FROM [dbo].[Groups] AS [Extent1]
    ORDER BY [Extent1].[LastUpdateTime] DESC

When I run this in a query in SQL Server, it works just fine, but the web app fails.

Out of curiosity, I just tried renaming the Description column to "blah". The web app only complained about LastUpdateTime.

I suspected the Connection String was pointing to a copy of the original .mdb file, but it's pointing to the SQLEXPRESS server.

Any suggestions?

dwilliss
  • 862
  • 7
  • 19
  • I would suggest if you are using DATABASE first approach then the easiest way to drop table from the model and re-create it again or update the model from the update EF model option. – Rajat Jaiswal May 23 '18 at 06:14
  • 1
    Even though you checked the connection string you're clearly not running against the right database. Did you check the right config file? – Gert Arnold May 23 '18 at 07:21
  • @GertArnold There's only one web.config, so I don't know where else it could be getting it from if there is. I know it's using the connection string, because I initially had problems when I changed it to connect to the server. It does *feel* like it's still using the original .mdf file though so you may be onto something – dwilliss May 23 '18 at 13:01

0 Answers0