开发者

Is there a tool to convert T-SQL Stored Procedures to C#? [closed]

开发者 https://www.devze.com 2023-03-07 04:59 出处:网络
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 2 years ago.

Improve this question

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号