tags:

views:

73

answers:

1

I have the following code:

public IEnumerable<MyClass> GetFirstData()
{
    return session.CreateCriteria<MyClass>()
        // ICriterions here
        .Future<MyClass>();
}

public IEnumerable<MyClass> GetSecondData()
{
    return session.CreateCriteria<MyClass>()
        // different ICriterions here
        .Future<MyClass>();
}

then:

var firstData = GetFirstData();
var secondData = GetSecondData();

foreach(var item in secondData)
    // whatever

But when this executes NHProf shows the two queries executing separately. Should I expect these to be performed in the same batch (database round-trip)? What am I doing wrong?

Thanks

A: 

No, NHibernate futures won't "combine" the queued queries (that would potentially create invalid queries). But it will send them together in a batch, so you will save network overhead.

Mauricio Scheffer
edited my crap use of terminology in the question. I didnt expect it to be a single query, rather two sql statements executed together (a batch?) returning two recordsets (which NH parses into the two IEnumerables). I see the two queries executed totally separately (as if i wasnt using `Future()`)
Andrew Bullock