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