Hi Greg
I have just tested a suggestion by Oren and it seems that it is in fact
possible to update an agg-root without modifying it.  All you have to do to
mark it dirty is to update its version....

public class Person
{
public Guid ID { get; set; }
public int Version { get; set; }
public string Name { get; set; }
}

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class name="BusinessClasses.Person, BusinessClasses" lazy="false"
table="People">
        <id name="ID" type="System.Guid" access="backfield">
          <generator class="guid.comb"/>
        </id>
        <version name="Version" access="backfield"/>
        <property name="Name" access="backfield"/>
      </class>
    </hibernate-mapping>


Guid key;

using (var session = sessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var person = new Person();
person.Name = "Pete";
session.Save(person);
transaction.Commit();
key = person.ID;
}

using (var session = sessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var person = session.Get<Person>(key);
person.Version = 999;
session.Save(person);
transaction.Commit();
key = person.ID;
}

Results in following SQL....

INSERT INTO People (Version, Name, ID) VALUES (@p0, @p1, @p2);
  @p0 = '1',
  @p1 = 'Pete',
  @p2 = '0c4eaeb7-4058-45af-96b6-9c0d00f5b1d0'

[Select]

UPDATE People SET Version = @p0, Name = @p1
WHERE ID = @p2 AND Version = @p3;
  @p0 = '2',
  @p1 = 'Pete',
  @p2 = '0c4eaeb7-4058-45af-96b6-9c0d00f5b1d0',
  @p3 = '1'

So it seems that NH picks up the change to Version as an indication that it
is dirty, but when it updates it sets it to OldVersion+1 rather than
PropertyValue+1 - Which seems to be exactly what we want!


Pete

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to