如何将LINQ语句转换为SQL查询? [英] How to convert LINQ statement to SQL query?

查看:851
本文介绍了如何将LINQ语句转换为SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

What is the equivalent SQL query fron following LINQ statement??

.DatasetProductInfo.Category.GetAccessibleRows().OrderBy(Function(x) If(Val(x.CatagoryId).Equals(0), Double.MaxValue, Val(x.CatagoryId))).ThenBy(Function(x) row.CatagoryId).Select()

Note:
Val() is the vb.net function that returns number(s) from the alphanumeric value. 
For example, Val(12foo) returns 12 only.

Thanks !

推荐答案

有一个很棒的工具叫做 LinqPad [ ^ ]。下载并安装它。免费版本绰绰有余。

准备一个正确的数据连接,以便您可以执行LINQ查询。此时单击SQL视图,您将看到生成的SQL语句(如此处 [ ^ ])。



但是,如果此查询在LINQ to Objects bot上运行,而不在LINQ to EF或LINQ to SQL上运行,则它也不会在LinqPad中运行。在这种情况下,您可能需要使用一些 SqlFunctions [ ^ ],或者如果这还不够。如果这仍然不够,你可以在SQL / EF上进行第一次传递(通过尽可能多地过滤),而不是在ToList()之后你可以将对象上的所有内容作为第二次传递。
There is a great tool called LinqPad[^]. Download, and install it. The free version will be more than enough.
prepare a proper data connextion so you can execute your LINQ query. At that point click to the "SQL" view, and you will see the generated SQL statements (like here[^]).

But if this query runs on LINQ to Objects bot not on LINQ to EF or LINQ to SQL, it won't run in LinqPad either. In this case you will probably need to use some SqlFunctions[^], or if this is not enough. If this is still not enough, you can have a first pass on SQL/EF (by filtering as much as you can), than after a ToList() you have everything that's available on Objects as a second pass.


如何将SQL语句转换为LINQ语句可以帮助它。我在结果窗口中找不到LINQ选项。
How to Convert SQL statement to LINQ statement can u help in it. I couldn't find the LINQ option in Result window.


这篇关于如何将LINQ语句转换为SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆