Code Refactoring

Entity Developer supports integration with Visual Studio refactoring that enables renaming of model objects. For example, when renaming an entity or complex type, refactoring will ensure that any references to that class are renamed across your solution. Refactoring is applicable to namespaces, classes and complex types as well as their properties, enums and their members; for LinqConnect and Entity Framework models it also applies to the context class and its properties.

Refactoring starts after you save your project. In case any conflicts occur, refactoring will not be performed.

note Note

Refactoring is available only in Entity Developer Visual Studio add-in.

For the purpose of the following example that illustrates refactoring operation, we create the Employee class in the model; the code we get is as follows:

      NorthwindModel.NorthwindEntities context = new NorthwindModel.NorthwindEntities();
      Employee emp = context.Employees.First();
      Console.Write(emp.Address);

Then we make the following changes in the model:

rename the class from Employee to EmployeeEntity;
rename class namespace from NorthwindModel to NorthwindNamespace;
rename context namespace from NorthwindEntities to NorthwindContext;
and rename the Address property to EmployeeAddress.

After this we save the project and the code changes as follows:

      NorthwindNamespace.NorthwindContext context = new NorthwindNamespace.NorthwindContext();
      EmployeeEntity emp = context.EmployeeEntities.First();
      Console.Write(emp.EmployeeAddress);

By default, refactoring is enabled, but it can be disabled for the sake of, for example, performance.

ExpandedToggleIcon        To disable refactoring do the following:

1.In the Visual Studio menu bar click the Tools menu and select the Options sub-menu.
2.In the navigation pane on the left, expand the Entity Developer node, then the Environment node and then select General.
3.Deselect the Refactoring the renamed model objects check box in the display area of the Options dialog box.

 


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.