[NHIbernate] using LINQPad to view NHIbernate generate SQL statements

Source: Internet
Author: User

In the previous article we mentioned that you can monitor the SQL scripts nhibernate send to the database by overriding the NHibernate Emptyinterceptor interceptor. See a friend today with the LINQPad tool for nhibernate generated SQL statement monitoring, try to feel more intuitive. Of course this is not the main function of LINQPad, but we can use this method to achieve our goal.

Next, let's look at how to use LINQPad to view the SQL NHibernate sent to the database.

1. Press F4 to enter Query Properties, or Query->query propertiesl. Add NHibernate and the entity-related DLL file you are using here.

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

3. Go back to the main interface, write the test code, and execute it.

This gives you a visual view of the resulting SQL statement and the results of the query.

Configuration config =NewConfiguration (). Configure (@"D:\Norton.Demo\NHibernate\Norton.Demo.NHibernate\NHibernate\hibernate.cfg.xml");varSessionfactory =CONFIG. Buildsessionfactory ();using(varSession =sessionfactory.opensession ()) {    varList = session. Createcriteria<product>()                    . ADD (Restrictions.eq ("Name","Apple"))                    . Uniqueresult<Product>(); List. Dump ();}
View Code

[NHIbernate] using LINQPad to view NHIbernate generate SQL statements

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.