Castle ActiveRecord:查看 SQL 的最简单方法是什么?
我试图让 Castle ActiveRecord 向我展示它生成的 SQL。我在这方面找到的各种博客提供了两种替代方案:
(1) 使用 NHibernate“show_sql”设置。问题是,我正在使用编程配置,就像这样。
var config = XmlConfigurationSource.Build(
DatabaseType.MsSqlServer2008, Settings.Default.StationManagerDbConnectionString);
config.IsRunningInWebApp = isRunningInWebApp;
config.PluralizeTableNames = true;
var modelAssembly = Assembly.GetAssembly(typeof(OneOfMyClasses));
ActiveRecordStarter.Initialize(modelAssembly, config);
通过编程配置,似乎没有办法指定“show_sql”。
(2) 使用log4net。但撇开 log4net 工作起来的痛苦不谈,我还没有找到一种方法来获取 SQL。我得到了大量的调试数据,其中 SQL 语句只是一小部分。
那么:有什么方法可以保留 Castle ActiveRecord 的编程配置,同时让 NHibernate 只输出 SQL?
编辑:这是我使用 log4net 的工作。但在我的 Web 应用程序的前两页中,调试窗口中会输出超过 14,000 行。如何更改此代码以仅获取 SQL?
var appender = new log4net.Appender.DebugAppender
{
Layout = new log4net.Layout.SimpleLayout(),
Name = "NHibernate.SQL",
Threshold = log4net.Core.Level.Debug
};
log4net.Config.BasicConfigurator.Configure(appender);
I'm trying to get Castle ActiveRecord to show me the SQL it generates. The various blogs I've found on this give two alternatives:
(1) Use the NHibernate "show_sql" setting. The trouble is, I'm using programmatic configuration, like this.
var config = XmlConfigurationSource.Build(
DatabaseType.MsSqlServer2008, Settings.Default.StationManagerDbConnectionString);
config.IsRunningInWebApp = isRunningInWebApp;
config.PluralizeTableNames = true;
var modelAssembly = Assembly.GetAssembly(typeof(OneOfMyClasses));
ActiveRecordStarter.Initialize(modelAssembly, config);
With programmatic configuration, there doesn't seem to be a way to specify "show_sql".
(2) Use log4net. But leaving aside what a pain log4net is to get working, I haven't found a way to get just the SQL. I get gobs and gobs of debug data, of which the SQL statements are just a small part.
So: Is there some way I can keep my programmatic configuration of Castle ActiveRecord but also get NHibernate to output just the SQL?
EDIT: Here's what I got to work with log4net. But in the first two pages of my web app, this spits out over 14,000 lines in the Debug window. How do I change this code to get only the SQL?
var appender = new log4net.Appender.DebugAppender
{
Layout = new log4net.Layout.SimpleLayout(),
Name = "NHibernate.SQL",
Threshold = log4net.Core.Level.Debug
};
log4net.Config.BasicConfigurator.Configure(appender);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够利用 NHibernate.SQL 记录器分离出 sql。
配置示例:
编辑:
You should be able to just separate out the sql by utilizing the NHibernate.SQL logger.
Example config:
Edit:
完成这项任务的最佳工具是 NHibernate Profiler (http://nhprof.com/)。
这是一个商业应用程序,但您可以免费试用 30 天。
The very best tool for the task is the NHibernate Profiler ( http://nhprof.com/ ).
It's a commercial application but you get 30 days free trial.