Update from 2017:
Realistically, the answer is no, and even if there were you should be extremely cautious of using it.
There are really only two ways to attack this problem:
a) Bite the bullet and convert everything manually and painstakingly and with some method of verification to check that everything continues to behave as intended, like unit/regression tests. Use tools like Linqer, if available, as assistance, to solve a part of the problem.
b) Start over from scratch.
There is no option c) to have something else handle everything neatly and automatically, and it could not possibly cover all cases. There are many things T-SQL can do that LINQ can't (updates, inserts and deletes spring to mind), and many things that you would be better off doing a different way in C# (like cursors).
Very few problems like this get well-engineered, exhaustive solutions that can be trusted not to regress functionality (like commercial VB6 to VB.NET converters that could justify spending enormous effort because of the sheer volume of potential customers out there, and where you can pick up a phone or a lawyer if something goes wrong), so if such a tool existed you should be extremely careful. The translation from the LINQ-compatible subset of SQL to LINQ is a bounded problem that is well-understood by the and I think Linqer can be trusted.
This question was trying to suss out a tool that could assist with option a) but I imagine many people reading this are looking for option c). There is a subset of this question and answer that is not a horrible idea, but it does not automate away the remaining burden, since even many of the simple stored procedures did more than querying in a LINQ-expressible form. It was still far too untenable to do option a) for any of the projects I mentioned.
Original question follows:
I have a few projects to maintain that use a lot of SQL Server stored procedures (in T-SQL). I know how to maintain them, but since there are many tools to automatically convert between different languages, I'm wondering if there's any tool to convert the stored procedures to C# code?
I do NOT want to convert them to CLR Stored Procedures; I simply want to migrate the logic in my data layer to the C# end of my project and automate the grunt work. Most of the stored procedures (maybe 70%?) are simple "SELECT * FROM table WHERE id = @id" affairs, and they could be done just as well with Entity Framework.
I know that it's not a straight line between T-SQL and C# as it is from VB.NET to C# and that conversion isn't as straightforward; you will need to introduce a data layer in C#, for example, and some things like cursors don't have corresponding concepts. I just want to move off of stored procedures without the repetitive manual labor if possible.
Since this has been put into question by faulty assumptions: I already know T-SQL, and given the code of any one of these stored procedures I could tell you what they do. There are very good practical reasons why I do not want the logic to continue residing in stored procedures.
Check out Linqer:
Linqer is a SQL to LINQ converter tool. It helps you to learn LINQ and convert your existing SQL statements.
Not every SQL statement can be converted to LINQ, but Linqer covers many different types of SQL expressions.
Because LINQ is a part of C#, it is sensitive to data types conversion. Linqer performs required type castings in the produced LINQ statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With