[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