Update from 2017:
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.
a)咬住子弹并手动和精心地转换所有内容,并使用一些验证方法来检查所有内容是否仍按预期运行,如单元/回归测试。使用Linqer等工具(如果有)作为帮助来解决部分问题。
b) Start over from scratch.
b)从头开始。
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).
没有选择c)让其他东西整齐自动地处理所有事情,并且它不可能涵盖所有情况。有很多事情,T-SQL可以做LINQ不能做的事情(更新,插入和删除想到的东西),以及许多你最好在C#中做不同的方式(比如游标)。
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.
很少有像这样的问题得到精心设计,详尽无遗的解决方案,可信赖不退回功能(如商业VB6到VB.NET转换器,由于潜在客户的庞大数量,以及你可以在哪里,可以证明花费巨大的努力是合理的如果出现问题,请拿起电话或律师),所以如果存在这样的工具,你应该非常小心。从LINQ兼容的SQL子集到LINQ的转换是一个有限的问题,并且我认为Linqer可以信任。
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.
这个问题试图找出一个可以帮助选项a)的工具,但我想很多读这篇文章的人都在寻找选项c)。这个问题和答案的一个子集并不是一个可怕的想法,但它不能自动消除剩余的负担,因为即使许多简单的存储过程也不仅仅是以LINQ可表达的形式进行查询。对于我提到的任何项目,做选项a)仍然太过难以置信。
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?
我有一些项目要维护使用很多SQL Server存储过程(在T-SQL中)。我知道如何维护它们,但由于有许多工具可以自动在不同语言之间进行转换,我想知道是否有任何工具可以将存储过程转换为C#代码?
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.
我不想将它们转换为CLR存储过程;我只想将数据层中的逻辑迁移到项目的C#端,并自动执行繁琐的工作。大多数存储过程(可能是70%?)都是简单的“SELECT * FROM table WHERE id = @id”事务,它们也可以与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.
我知道它不是T-SQL和C#之间的直线,因为它是从VB.NET到C#,并且转换不是那么简单;例如,您需要在C#中引入数据层,而像游标这样的东西没有相应的概念。我只是希望在没有重复的手工劳动的情况下移出存储过程。
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.
因为这已经被错误的假设所质疑:我已经知道T-SQL,并且考虑到这些存储过程中的任何一个的代码,我可以告诉你他们做了什么。我不希望逻辑继续驻留在存储过程中有很好的实际原因。
1 个解决方案
#1
2
Check out Linqer:
查看Linqer:
Linqer is a SQL to LINQ converter tool. It helps you to learn LINQ and convert your existing SQL statements.
Linqer是一个SQL到LINQ转换器工具。它可以帮助您学习LINQ并转换现有的SQL语句。
Not every SQL statement can be converted to LINQ, but Linqer covers many different types of SQL expressions.
并非每个SQL语句都可以转换为LINQ,但Linqer涵盖了许多不同类型的SQL表达式。
Because LINQ is a part of C#, it is sensitive to data types conversion. Linqer performs required type castings in the produced LINQ statements.
由于LINQ是C#的一部分,因此它对数据类型转换很敏感。 Linqer在生成的LINQ语句中执行所需的类型转换。
#1
2
Check out Linqer:
查看Linqer:
Linqer is a SQL to LINQ converter tool. It helps you to learn LINQ and convert your existing SQL statements.
Linqer是一个SQL到LINQ转换器工具。它可以帮助您学习LINQ并转换现有的SQL语句。
Not every SQL statement can be converted to LINQ, but Linqer covers many different types of SQL expressions.
并非每个SQL语句都可以转换为LINQ,但Linqer涵盖了许多不同类型的SQL表达式。
Because LINQ is a part of C#, it is sensitive to data types conversion. Linqer performs required type castings in the produced LINQ statements.
由于LINQ是C#的一部分,因此它对数据类型转换很敏感。 Linqer在生成的LINQ语句中执行所需的类型转换。