I'm adding a bulk updater functionallity in an application, basically
the customer is supposed to be able to provide an Excel file with
updated information from another system, which will be parsed and then
we'll modify all affected rows in the database. Anyway, I noticed some
odd behavior, and maybe there's a reason for it but I'm still
curious...

Let's say we have a simple domain model like this:

public class Zoo : Entity {
    public virtual bool IsOpen { get; set; }
    public virtual ISet<Animal> Animals { get; set; }
}

public class Animal : Entity {
    public virtual string AnimalType { get; set; }
    public virtual bool IsHungry { get; set; }
    public virtual int Age { get; set; }
    public virtual Zoo Zoo { get; set; }
}

And let's say we've set the batch size to 25. Now If I just load a
bunch of Animals into memory, and do something like this:

using(var session = sf.OpenSession())
using(var tx = session.BeginTransaction())
{
    foreach(var animal in animals) {
        session.Lock(animal, LockMode.None);
        animal.Age += 1;
    }
    tx.Commit();
}

When we issue the commit, everything works as I expected, we're
getting updates in batches of 25. Now to the issue, let's say we
instead do the following:

using(var session = sf.OpenSession())
using(var tx = session.BeginTransaction())
{
    foreach(var animal in animals) {
        session.Lock(animal, LockMode.None);
        animal.Zoo.IsOpen = !(animal.Zoo.IsOpen);
        animal.Age += 1;
    }
    tx.Commit();
}

Now, with this batching seems to be disabled, they are updated one
after another. Is this due to the cascading? Is this expected? If it
is, why? Or am I simply doing something wrong? I know I could do it in
two transactions, just updating the animals in one transaction and the
Zoos in another transaction, and batching would work just fine. I'm
just curious about this behavior I'm seeing with this in one
transaction though.

btw, this is with NHibernate version 3.2.0.1002 (the version currently
available in NuGet as of this post).

Cheers!

-- 
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.

Reply via email to