NHibernate:如何在 Windows 控制台中显示生成的 SQL 语句
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.Database(Database)
.TrustedConnection()
.Server(Server)
).ShowSql())
.ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TeamMap>()).BuildConfiguration();
我有一个网络应用程序。此配置不起作用。
我还有一个控制台应用程序,负责写出所有生成的 SQL。
如何获取生成的 SQL 命令?
提前致谢!
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.Database(Database)
.TrustedConnection()
.Server(Server)
).ShowSql())
.ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TeamMap>()).BuildConfiguration();
I have a web application. This configuration does not work.
I also have a Console application that shall be responsible to write out all generated SQL.
How can I get the generated SQL commands?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 NHibernate 已经通过 log4net 记录 SQL,因此这是最简单的方法。由于您不需要日志文件,请配置跟踪附加程序并通过 ASP.NET 跟踪。通过在代码中进行配置,您可以确保当您不再需要它时它就会消失。
如果您只需要 SQL 语句,则只需要来自 NHibernate.Loader.Loader 的 Info 级别的消息。
Trace 是 ASP.NET 中的一个日志记录工具,其结果可以在生成消息的页面末尾看到,也可以通过 ~/trace.axd 查看。
如果跟踪输出对于您的需要来说太冗长,或者您不需要出于任何原因不想这样做,还有其他附加程序可以通过网络发送日志消息。
UDPAppender 通过 UDP 通过网络发送日志消息。
TelnetAppender 允许您通过 telnet 连接到 log4net。要查看消息,您可以从控制台窗口远程登录到您的应用程序。
Since NHibernate already logs SQL via log4net, that is the easiest approach. As you don't want log files, configure the trace appender and view the results via the usual methods for ASP.NET Trace. By configuring in code, you can be sure it is gone when you no longer need it.
If you just want the SQL statements, you only want messages from NHibernate.Loader.Loader at Info level.
Trace is a logging facility within ASP.NET, the results of which can be seen either at the end of the page that generated the messages, or via ~/trace.axd
If the trace output is too verbose for you needs, or you don't want to go that way for any reason, there are other appenders that can send the log messages over the network.
The UDPAppender sends log message over the network via UDP.
The TelnetAppender lets you connect to log4net via telnet. To view the messages, you can telnet to your application from a console window.