NHibernate config properties in Fluent NHibernate

2019-05-22 15:41发布

I am considering using Fluent NHibernate for my project and I haven't found any documentation on whether FH supports NHibernate settings such as show_sql and prepare_sql. I could live without show_sql in a pinch, but prepare_sql is important for ensuring good performance at run time.

Can anyone tell me if it's possible to configure these settings in Fluent NHibernate?

2条回答
太酷不给撩
2楼-- · 2019-05-22 16:15

Yes, you can.

Fluently.Configure()
    .Database(ConfigureDatabase())
    .Mappings(ConfigureMapping)
    .ExposeConfiguration(ModifyConfiguration)
    .BuildConfiguration();

And now in ModifyConfiguration method you have plain NHibernate's Configuration object to modify

private void ModifyConfiguration(Configuration configuration)
{
    // set parameters here like this:
    configuration.Properties["show_sql"] = "true";
}
查看更多
在下西门庆
3楼-- · 2019-05-22 16:18

Some of the settings are exposed through the fluent API.

See here for examples: Database Configuration

Anything that isn't supported through specific fluent calls can be set by manipulating the native NHibernate.Cfg.Configuration object. Either way you can do everything in code that you can with the configuration file.

查看更多
登录 后发表回答