Suppose there is a model that was generated from the database. Code was written using this model.

At one point there is a need to change the name of the column in the database.

If I change the name of the column and perform an update from the database, then in effect a new property will appear.

As a result, the entity will have 2 properties: the property with the old name, and the property with the current name.

How do I refactor the code itself, so that where the old property was used, the new one would be used?

  • Are you sure that the old property will not disappear? Do you use code first or db first? I think you need a migration . - VladD
  • I use db first - iluxa1810
  • Well, then change the base and delete the entity-classes and regenerate them, business! - VladD
  • @VladD, so if you regenerate the classes, wouldn't the floor of the code fail, so where was this property used? Or will the studio understand and rename it itself? - iluxa1810
  • No, do not rename. Then, before deleting, just rename the property via F2 (or Edit -> Refactor -> Rename). - VladD

1 answer 1

If the code is compiled exclusively, then mark the old property with the Obsolete attribute and correct as the time and possibilities of the warning.

If there are some inconvenient strings that are not so easy to find - you can now simply redirect the old property to a new, something like

ObsoleteProperty { get { return NewProperty; } set { NewProperty = value; } }