Last post Aug 25, 2018 12:24 PM by mgebhard
Aug 24, 2018 09:28 PM|tinac99|LINK
I changed a database table (both updated and dropped and recreated the table). Somehow, running the command in the package manager console:
Update-Database -context <contextname>
says that "No migrations were applied. The database is already up to date."
So, I changed the context manually.
When I execute context.savechanges(), it says "invalid column name 'column1'", but column1 does not exist in the current table. It did exist in the previous version before I dropped and recreated the table. 'column1' is a foreign key - referencing another
I have not been able to establish this FK relationship in the context
entity.HasOne(d => d.TableNameForeignKeyReferenceTable)
.WithMany(p => p.TableName)
.HasForeignKey(d => d.foreignKeyColumn)
entity.HasOne(d => d.PersonAliasPerson) /* compiler is not recognizing this */
.WithMany(p => p.PersonAlias)
.HasForeignKey(d => d.PersonId)
Aug 25, 2018 11:50 AM|DA924|LINK
So what can't you delete the EF model out of the project and regenerate it fresh based on the existing DB schema? That's what I would do if it were me. But I don't use EF code first.
Aug 25, 2018 12:24 PM|mgebhard|LINK
The first step is learning "Code First". Don't delete a table because then your migrations snapshot files become out of sync with the database. In Code first you back out database updates then reapply if necessary. Like undo.
If you want to make changes directly in the DB then you'll need to re-scaffold the entities after every change.
I recommend that you go through the following site to learn EF Core.