Use LinqPad to view the SQL statements generated by nhib.pdf

Source: Internet
Author: User
Tags log4net

To use Nhibernate for development, you must view and analyze the SQL statements generated by Nhibernate to view the SQL statements generated by Nhibernate. You can use NHProfiler and log4net. But NHProfiler is charged (of course, in tianchao, you know ......), Log4net configuration is troublesome. Today, I found a tool LinqPad when I checked the information about Linq to Nhibenate on the Internet. So I found the relevant resources and found that it can actually view the Nhibenate statement. Let's talk nonsense. Let's take a look at the following methods!

1. Download LinqPad, address: http://www.linqpad.net/

2. Configure LinqPad and run LinqPad. Choose Query> Query Propeties from the menu. On the tab, select Additional References and click "Browse ..." Click to select the required Dll in the project.

Dll includes: Database driver dll, Entity dll ing dll (Entity in the figure), and Dll related to nhibernate.

3. On the "Additional Namespace Imports" tab, click "Pick from assemblies" in the upper right corner and select the corresponding Namespace.

4. Test code writing

It is really convenient to see not only the generated SQL statements but also the query results!

Code:

Configuration configuration = new Configuration (). replace Configure (@ "with hibernate. cfg. xml Path "); var SessionFactory = configuration. buildSessionFactory (); using (var session = SessionFactory. openSession () {var list = session. query <Role> (). select (m => new Role () {Id = m. id, Privileges = null, ReMark = m. reMark, RoleName = m. roleName }). toList (); // display the result list. dump ();}

View Code

 

 

 

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.