NHibernate: a little trick when working with Oracle or PostgreSQL
ADO.NET providers for Oracle, PostgreSQL and maybe others have one unpleasant feature, which may affect the performance of your application if you are requesting from the server large amounts of data: they do not cache the method calls IDataReader.GetOrdinal. As it turned out it is very critical for NHibernate, but fortunately, the developers of NHibernate (or rather Hibernate) this problem was noticed already decided.
But this feature has remained unnoticed and almost not documented.
In order to NHibernate to enable caching, call an IDataReader.GetOrdinal in hibernate.cfg to set the option "adonet.wrap_result_sets" to the value "true":
the
C FluentNHibernate this is done as follows:
the
_ExposeConfiguration_ method adds actions that will be called on the object NHibernate.Cfg.Configuration when calling BuildConfiguration. So the above code will be similar to the following:
the
the
Article based on information from habrahabr.ru
But this feature has remained unnoticed and almost not documented.
In order to NHibernate to enable caching, call an IDataReader.GetOrdinal in hibernate.cfg to set the option "adonet.wrap_result_sets" to the value "true":
the
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<!-- other options -->
<session-factory name="MySessionFactory">
<!-- other session factory options -->
<property name="adonet.wrap_result_sets">true</property>
</session-factory>
</hibernate-configuration>
C FluentNHibernate this is done as follows:
the
var config = Fluently.Configure()
.ExposeConfiguration(c = > c.SetProperty(Environment.WrapResultSets, "true"))
.Database(db)
/* other configuration */
.BuildConfiguration();
_ExposeConfiguration_ method adds actions that will be called on the object NHibernate.Cfg.Configuration when calling BuildConfiguration. So the above code will be similar to the following:
the
var config = Fluently.Configure()
.Database(db)
/* other configuration */
.BuildConfiguration();
config.SetProperty(NHibernate.Cfg.Environment.WrapResultSets, "true");
related Links
the
Комментарии
Отправить комментарий