question

BillyJacobs-8371 avatar image
0 Votes"
BillyJacobs-8371 asked Cathyji-msft edited

Entity Framework queries dropped column

Setup:

I have a project using EF core 5.0 in a .net 5.0 project.

The project has a subclassed DbContext class which contains the list of DBSets and then the OnModelCreating which maps the classes to the appropriate tables.

There are no migrations.

Problem:

I removed 2 columns from one of the entities, but when EF queries the database it still adds these 2 columns to the query and I get an error saying invalid column .... The generated queries that show in the console output have the invalid columns.

I verified there are no references to either of these 2 columns in the code base or in any object in the database. I used the following query to check. I checked to see if there were any views etc.

 select * 
 from sys.all_objects AO 
     join sys.all_columns AC on AC.object_id=AO.object_id
     where ac.name like '%LocationId%' or ao.name like '%LocationId%'
     order by ac.name


What causes it to remember these deleted columns and how to I force EF to forget them?

Thanks,

Billy Jacobs

dotnet-entity-framework-core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

how to I force EF to forget them?

You have to refresh the model from database.
Open the EF model, right-mouse click on background => Refresh model from database.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.