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.
Apparently this feature will be available in version 4.1.0, and recently added in this checkin,
according to the documentation it's configured as follows