How to know query generated by Fluent NHibernate

后端 未结 8 1417
萌比男神i
萌比男神i 2020-12-30 00:07

I am using linq to Nhibernate to fire some select query to data base.

My question is, how do I know, the query generated by Fluent NHibernate?

8条回答
  •  梦毁少年i
    2020-12-30 00:35

    I have found 4 options to know sql query in nhibernate and fluent nhibernate.

    1. Log - Joey V. said in answer of this same question.
    2. ShowSql - Kevin Berridge said in answer of this same question.
    3. NHProf - This is a awesome profiler. NHProf
    4. Intercepter - It is really good to see sql. we can put it in our Output of Visual Studio and even in log file.

      ISessionFactory sf = Fluently.Configure()
              .Database(MySQLConfiguration.Standard.ConnectionString(ConnectionString).ShowSql())
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf())
              .ExposeConfiguration(c => c.SetInterceptor(new ABCInterceptor()))
              .BuildSessionFactory();
      
      
      public class ABCInterceptor : EmptyInterceptor
      {
          public override NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
          {
             Trace.WriteLine(sql.ToString());
             return sql;
          }
       }
      

提交回复
热议问题