EF Core doesn't recognize new column name from database

206 Views Asked by At

Used scaffolding to connect to my database (mapping to a view). To the same DbContext I manually added two DbSets for a stored procedure.

The first stored procedure is working perfectly. In one of the stored procedures, the result set contained two equally named columns (named text_content). My colleague who created the stored procedure renamed one of the columns (since the equal column names got me an error). After that I still get the same error:

System.ArgumentException: An item with the same key has already been added. Key: text_content

It seems like the DbContext doesn't recognize the change made in the database. If I create a brand new project (Blazor server), scaffold again (the way I did with the other project), the error is gone.

I'm using EF Core 7.

Thank you for any help.

I tried to use migrations but it seems like only changes made in the code can be migrated to the database, and not vice versa, is that true or am I missing something here? How can I "pull the changes from the database" to my code?

2

There are 2 best solutions below

1
ASPDev On

You can edit the storedprocedure-result.cs and change the column name manually and build your project or right click your project and choose reverse engineer and click ok and build your project.

ReverseEngineer

0
ASPDev On

Test SQL connection and check whether you included your SP in the EFcore Power tool. EFCoreToolImg