Hello
I need to iterate over a large collection of elements (More than can
fit in memory).
As such I'd like to use an IEnumerable and evict the elements from
cache as soon as they've been processed.
The code I have results in n+1 select queries. To have a more
controllable enviroment I created an empty project+database, added 10
TestModel entities and iterate over them using the following code:
[code]
ISession sess =
NHibernateSessionManager.Instance.GetSession();
IQuery query = sess.CreateQuery("from TestModel");
var coll = query.Enumerable<TestModel>();
foreach (TestModel tm in coll)
{
// Do magic
sess.Evict(tm);
}
[/code]
This results in the following SQL being executed by NHibernate:
[code]
NHibernate: select testmodel0_.Id as x0_0_ from TestModels testmodel0_
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'1'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'2'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'3'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'4'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'5'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'6'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'7'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'8'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'9'
NHibernate: SELECT testmodel0_.Id as Id1_0_, testmodel0_.Value as
Value1_0_ FROM TestModels testmodel0_ WHERE testmodel0_....@p0; @p0 =
'10'
[/code]
Obviously, this is not ideal.
My configuration section looks as follows:
[code]
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</
property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property name="connection.connection_string">....</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
[/code]
The mapping file:
[code]
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Test.Model" assembly="Test">
<class name="TestModel" table="TestModels">
<!-- Id -->
<id name="Id" type="Int64">
<column name="Id" not-null="true"/>
<generator class="increment" />
</id>
<property name="Value">
<column name="Value" sql-type="text" not-null="true" />
</property>
</class>
</hibernate-mapping>
[/code]
How can I make NHibernate batch-select X elements each time?
Ideally I would like to process an IEnumerable which automaticly
evicted elements once they had been MoveNext()'ed past, and batch-
fetched a number of objects at a time. I suspect NHibernate can do
this, and that I just need to find out how to do it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---