[Nhibib] use LINQPad to view NHIbernate to generate an SQL statement.

Source: Internet
Author: User

[Nhibib] use LINQPad to view NHIbernate to generate an SQL statement.

In the previous article, we mentioned that we can rewrite the EmptyInterceptor interceptor of NHibernate to monitor the SQL scripts sent to the database by NHibernate. Today we can see a friend using LINQPad to monitor the SQL statements generated by NHibernate, after trying it, I felt more intuitive. Of course this is not the main function of LINQPad, but we can achieve our goal through this method.

Next, let's take a look at how to use LINQPad to view the SQL statement that NHibernate sends to the database.

1. Press F4 to enter Query Properties or Query-> Query Propertiesl. Add the dll file about NHibernate and the Entity you are using here.

 

 

2. on the Additional Namespace Imports tab, click Pick from assemblies to add the Namespace used.

 

3. Return to the main interface, write the test code, and execute the code.

In this way, you can intuitively see the generated SQL statements and query results.

Configuration config = new Configuration (). configure (@ "D: \ Norton. demo \ NHibernate \ Norton. demo. nhib.pdf \ hibernate. cfg. xml "); var SessionFactory = config. buildSessionFactory (); using (var session = SessionFactory. openSession () {var list = session. createCriteria <Product> (). add (Restrictions. eq ("Name", "Apple ")). uniqueResult <Product> (); list. dump ();}View Code

 

Related Article

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.