Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking to design a tool to Translate Business logic from Stored Procedures to C# Business Layer [closed]

Tags:

c#

oracle9i

Without getting into a discussion about whether the business logic should be in the database or at the application layer, since it has been covered elsewhere.

My team is translating 100K+ lines of PL/SQL code and moving the logic from the database into the application. We were using VB6 with straight calls to Oracle 9i Stored Procedures and Ad-hoc queries and are now using C#, .net 3.5, Winforms with NHibernate to an Oracle 9i database.

We have already found a wonderful tool to assist in converting the Ad-hoc queries, SmartCode, but it only creates code based on Tables and Views. We are looking for a tool to assist in converting the Stored Procedures.

The Stored Procedures have most of the Business logic in them that we want to migrate to the application layer. We are wondering if there are any tools to convert the Stored Procedures into C# code.

Assuming there are none, what would be the best place to start if we develop the tool in-house/open source. Is there another similar system with similar goals that could be used as a starting place?

Accepted Answer UPDATE: I have selected scope-creep's answer, because it appears to be the best method for implementing the issue presented in the question. For those that deal with this same issue, I heartedly recommend Adam's response, as he has strongly advocated against the use of a tool and provides a strong rationale. He has also provided the most interaction with this question and had the most up-voted response.

Thank you to everyone for your help and dialog.

like image 632
Lucas B Avatar asked Jul 21 '10 14:07

Lucas B


People also ask

Can we write business logic in stored procedure?

"The default stance in designing an application should be that business logic is held in the application code, NOT in database stored procedures. Only move business logic into StoredProcedures as performance needs required. "

Can we write stored procedure in C#?

That is, you can create a stored procedure or UDF as a method in a C# class.

How do I create a stored procedure in Visual Studio?

Add a stored procedure item to your database project by right-clicking the project and selecting Add, New Item. From the Add New Item dialog, you select the SQL CLR C# category and then the SQL CLR C# Stored Procedure project item, as shown in Figure 13.29.

Why you shouldn't use stored procedures?

Stored procedures promote bad development practices, in particular they require you to violate DRY (Don't Repeat Yourself), since you have to type out the list of fields in your database table half a dozen times or more at least. This is a massive pain if you need to add a single column to your database table.


Video Answer


1 Answers

I don't believe there are any converters for SQL to C#.

As for approaching the creation of such a tool, I would first say, don't... your business requirement sounds like it is to get the logic into C#.

Depending on the state of the application, you can do this in many ways: one sproc at a time; logical entities at a time (all customer logic, etc); whole hog; agile-ish where you leave the sprocs alone for the time being and call straight into them from C#, and then slowly take one of the prior approaches - always leaving yourself with a functioning application.

Loaded question really :-)

I personally would first try to get it working in C# straight calling into the sprocs. Then take logical entities, as you will find they may reference other sprocs. Doing a sproc at a time will fragment your C# logic during development and add extra overhead to the creation of business classes.

The strength in a C# domain model is the clear boundaries of responsibility and grouping of behaviour into your logical entities - so taking a sproc at a time, you will not see the bigger picture. Using a converter, it will end in unreadable, unmanageable code that you then have to learn - something you don't need to do if you created it in the first place.

So my conclusion, if there is one, is to save yourself time in the future and take this as an opportunity to redesign your business layer - as you likely have knowledge and experience of the system's production behaviour from out in the wild, so the conversion can factor in any lessons learnt.

Update: it turns out you have tooling options for the conversion. The only thing I will say to that approach is this: the resulting code is not going to be pretty. You have the benefit that your current SQL is understood by the development team - they know the code. A code generator is going to produce 100% new code that no one knows. Learning curve... as you are going to need to verify the output of the tool to make sure it isn't mutating your logic - no tool is infallible.

If you decide to use the tool, I can only suggest to break the conversion down into very, very small parts (presumably the smallest is going to be a script (or perhaps even batch within a script)). When you have a small set of conversion results, integrate this into the application and pass it through a review process.

like image 181
Adam Houldsworth Avatar answered Oct 28 '22 18:10

Adam Houldsworth