So... already said it:
How to change FlushMode to Commit in C#?
I mean, In Fluent NHibernate FlushMode by default is setted as Auto.
So... to set FluentMode to Commit, I need to open session and then change It:
var someSessionFactory = ... bla bla ..;
var session = someSessionFactory.OpenSession();
session.FlushMode = FlushMode.Commit;
This will work but... this will mean that I need to call method which contains FlushMode.Commit each time I am opening session.
To inicialize sessionFactory I have several wraps (meant to set it only once and then auto use it when new context is opened), which means I can't just open session directly every time I want without digging into factory type and etc.
Is there a way to change default FlushMode from Auto to Commit? Is there a way to do it in var sessionFactory = Fluently.Configure(). ... ?
EDIT:
Tried seccond thing
public void Initialise(params Assembly[] mappingAssemblies)
{
this._sessionFactory = Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2008
.ConnectionString(this._connectionString)
.AdoNetBatchSize(10)
.QuerySubstitutions("true 1, false 0, yes 'Y', no 'N'"))
.Cache(c => c.Not.UseSecondLevelCache().Not.UseQueryCache())
.Mappings(m =>
{
foreach (Assembly asm in mappingAssemblies)
{
m.FluentMappings.AddFromAssembly(asm);
m.HbmMappings.AddFromAssembly(asm);
}
})
.ExposeConfiguration(ModifyConfiguration)
.BuildSessionFactory();
var session = _sessionFactory.OpenSession();
}
public void ModifyConfiguration(NHibernate.Cfg.Configuration configuration)
{
configuration.Properties["default_flush_mode"] = FlushMode.Commit.ToString();
}
I called _sessionFActory.OpenSession() to see if FlushMode has changed and... Nope. Still FlushMode is Auto, instead of Commit.
There is no way how to configure default FlushMode for ISession. The way I do that, and the way which could be found in common, is step into
ISessionFactory.OpenSession()(IoC, MVC AOP Filter, Web API delegate) and assign the FlushMode(manually)Check these:
The property ISession.FlushMode as defined below:
and it's the default implementation snippet:
is not set anyhow during the ISessionFactory.OpenSession() call.
ORIGINAL, not working approach
The documented
<hibernate-configuration>settingdefault_flush_modeis not supported.So, we have these configuration properties available for<hibernate-configuration>(default / not fluent configuration settings):3.5. Optional configuration propertiesand based e.g. on this Q & A:
NHibernate config properties in Fluent NHibernate
we can do: