Database component Hxj.data (10) (SQL for Output component execution)

Source: Internet
Author: User

TX message asked the front of the SQL is how the page, read this article you will know.

Component can output executed SQL to facilitate viewing SQL generated statements for problems.

To output SQL by registering events

DbSession.Default.RegisterSqlLogger(database_OnLog);

private string sql;
void database_OnLog(string logMsg)
{
   //保存执行的DbCommand (sql语句和参数)
   sql += "<br />" + logMsg;
}

and then by executing

DbSession.Default.UnregisterSqlLogger (Database_onlog); To unregister the registered event.

Here is an example of asp.net

DbSession.Default.From<Products>()
         .InnerJoin<Suppliers>(Suppliers._.SupplierID == Products._.SupplierID)
         .Page(10, 2)
         .Select(Products._.ProductID, Products._.ProductName)
         .ToDataTable();

The SQL statement that executes the above statement output is as follows:

SELECT  * FROM
( SELECT  TOP 10 * FROM
( SELECT  TOP 20 [Products].[ProductID],[Products].[ProductName]
FROM [Products]
INNER JOIN [Suppliers]
ON ([Suppliers].[SupplierID] = [Products].[SupplierID])
ORDER BY [Products].[ProductID] ASC) AS tempIntable
ORDER BY [ProductID] DESC) AS tempOuttable
ORDER BY [ProductID] ASC

One more.

Dbsession.default.from<products> (). Where (products._. CategoryID = 2). Tofirst ();

The resulting SQL statement is as follows

Text:
SELECT TOP 1 * FROM [Products] WHERE [Products].[CategoryID] = @ae2b9c6a112545e5b56fa6dc70f32ac1
Parameters:
@ae2b9c6a112545e5b56fa6dc70f32ac1[Int32] = 2

This component generated SQL statements can be at a glance, the output of SQL statements is also greatly facilitated debugging.

The next section describes the generation of whereclip (conditions).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.