The ADO.NET providers for
Oracle ,
PostgreSQL, and perhaps others have one unpleasant feature that can affect the performance of your application if you request large amounts of data from the server: they do not cache
IDataReader.GetOrdinal method calls. As it turned out, this is very critical for
NHibernate , but, fortunately, the developers of NHibernate (or rather
Hibernate ) have noticed this problem and have already solved it.
But this feature went unnoticed and almost not documented.
In order for NHibernate to enable the caching of
IDataReader.GetOrdinal calls, it is necessary to set the “adonet.wrap_result_sets” option to “true” in hibernate.cfg:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory name="MySessionFactory"> <property name="adonet.wrap_result_sets">true</property> </session-factory> </hibernate-configuration>
')
Using
FluentNHibernate, this is done like this:
var config = Fluently.Configure() .ExposeConfiguration(c => c.SetProperty(Environment.WrapResultSets, "true")) .Database(db) .BuildConfiguration();
The _ExposeConfiguration_ method adds the actions that will be invoked on the
NHibernate.Cfg.Configuration object when the
BuildConfiguration method is
called . Thus, the code above will be similar to the following:
var config = Fluently.Configure() .Database(db) .BuildConfiguration(); config.SetProperty(NHibernate.Cfg.Environment.WrapResultSets, "true");
Related Links