System Object Replacement Strategies

We are currently starting to replace the ADO.NET stack in our C # Linq application.

Since the application was not archived with a level of data abstraction, there are ADO calls at the entire level of each application, to the extent that separating any one object and trying to convert it to Linq means that you start the labyrinth of rabbit holes.

What I ask for is strategies or approaches to solving such wholesale system changes, while ensuring proper testing and a minimum period for dropping tools (changing the shelf at the time of notification and returning to it later).

We played with the following:

  • Create a mirror object of each object with new code = must support 2 code bases until complete conversion
  • Prefix all ADO function function names with ADO_ and create Linq versions with the original name
  • To be able to use ADO or Linq and wrap each ADO call with if (FLAG) {ADO} else {Linq} =, you need to return after the conversion and delete all ADO refs

Each sentence is still worthy of cringe.

What can you guys / gala have to offer?

NOTE. I removed '(ADO to Link)' from the header because I am looking for more general answers and methods, and not just for converting ADO to Linq, used as an example here.

+6
c # linq
source share
2 answers

Before you make any changes, you must have automatic unit tests. In fact, you should not make changes to code that does not extend to unit tests of at least 80%.

In the real world, unit tests often do not exist. On the other hand, performing any refactoring without unit tests can completely ruin your code, which makes Management even less likely that you will make changes in the future. What to do?

Using a tool like ReSharper, you can start by using some “safer” refactoring. With caution, there is no reason why you won’t be able to repeatedly use the “Extract Method” to move your ADO.NET code into separate methods: “Make the Static Method” if it was not static yet, either “Move the Method” or “Make non-static method "to move the method to a separate class.

Once you exit the code, you can start writing automated tests. At this stage, they do not need to be “unit tests” in the strict sense of the word. In particular, these tests must be allowed to work with the database.

When you are left with only code that cannot be easily tested, you can very carefully begin to make this code more testable. You can do things like sets of sets of static methods into instance methods of new classes. You can also start injecting dependency injection to simplify testing using mock objects. But be very careful here - you are modifying code that does not have automated tests, and you will use refactoring that can really break stuff.

After you have done an adequate code test, you can reorganize the code to better understand it and then change it to use LINQ if you want.

+3
source share

You can still use all your stored procedures / functions created for your solution using Linq2SQL. Using something like the strategies expressed in the Micheal Feather Working with Legacy Code , you can create borders around application areas and update them within those boundaries.

The strategy that I used in the past is to maintain / ignore the database and its objects. Then I slowly repeat the various ADO calls and replace the Linq2SQL calls until the entire application uses Linq2SQL. Then it’s easier for me to convert previous ADO calls that opened and passed DataSets / DataTables to more suitable objects.

Another approach (for the heavy DataSet / DataTable solutions) is to save the ADO calls and instead use the AsQueryable() and / or OfType<T>() extension methods to convert the ds / dt elements to the appropriate objects and then aggregate these turns into a more cohesive DAL.

+2
source share

All Articles