如何从nHiberhate获得格式良好的查询?

时间:2012-09-09 17:04:27

标签: nhibernate

我希望nHibernate在我的日志中给我一个干净的查询。而不是像这样的一行:

select project2x0_.proj_id as proj1_10_0_, projwbs1_.wbs_id as wbs1_11_1_, project2x0_.proj_short_name as proj2_10_0_, project2x0_.project_flag as project3_10_0_, projwbs1_.wbs_name as wbs2_11_1_, projwbs1_.wbs_short_name as wbs3_11_1_, projwbs1_.proj_id as proj4_11_1_, projwbs1_.proj_id as proj4_0__, projwbs1_.wbs_id as wbs1_0__ from project project2x0_ left outer join projwbs projwbs1_ on project2x0_.proj_id=projwbs1_.proj_id where @p0=1;@p0 = True [Type: Boolean (0)]

我更希望以更易读的形式看到它:

select project2x0_.proj_id as proj1_10_0_
, projwbs1_.wbs_id as wbs1_11_1_
, project2x0_.proj_short_name as proj2_10_0_
, project2x0_.project_flag as project3_10_0_
, projwbs1_.wbs_name as wbs2_11_1_
, projwbs1_.wbs_short_name as wbs3_11_1_
, projwbs1_.proj_id as proj4_11_1_
, projwbs1_.proj_id as proj4_0__
, projwbs1_.wbs_id as wbs1_0__ 
from project project2x0_ 
left outer join projwbs projwbs1_
  on project2x0_.proj_id=projwbs1_.proj_id 
where @p0=1;

; @ p0 = True [Type:Boolean(0)]

特定字段都可以在一行上,这很好。但我真的很想看到FROM,JOIN和WHERE语句被拔出。

我希望这是在log4net输出中,而不是通过某些第三方工具。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在Configuration对象上将“format_sql”属性设置为true会得到类似于您想要的输出。