Reputation: 191
I use a third party database with Entity Framework 6. This works fine; however, when a table within my model is changed (three columns were deleted), my program throws an exception:
System.Data.SqlClient.SqlException: Invalid column name '<deleted column>'
I don't use any of these columns. I only read them from the database. I can update my model, but then when there is another change in a table, my program will crash again. How can I modify my program so that it won't crash on the next database change?
Upvotes: 0
Views: 271
Reputation: 191
It will still crash though if any of your entities/properties gets changed/deleted
Upvotes: 0
Reputation: 6491
You can use a Code First approach starting from database (generate classes from database). At the end of class generation you can delete entities that you don't need (i.e. entities related to all unused tables) or properties related to unused fields.
Disable migrations.
You can also delete intermediate files generated by EF code generation (files different from .cs files).
At this point, any changes to database that not affects mapped classes/properties does not cause errors in EF.
Upvotes: 1