Entity Framework queries dropped column

Billy Jacobs 6 Reputation points


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.


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?


Billy Jacobs

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
711 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Olaf Helper 42,386 Reputation points

    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.

    0 comments No comments