Well .. there is an answer to this :) .
You have to set the value in that state array AND on the entity. It
took me an hour to realize this even though I found the following
code :
var audit = @event.Entity as IAudit;
if(audit == null)
return false;
var time = DateTime.Now;
Set(@event.Persister, @event.State, "RecordStamp",
time);
audit.RecordStamp = time;
This doesn't generate the extra update . I just couldn't see the
difference .
The Set method has nothing special :
private void Set(IEntityPersister persister, object[] state, string
propertyName, object value)
{
var index = Array.IndexOf(persister.PropertyNames,
propertyName);
if (index == -1)
return;
state[index] = value;
}
So : you have to set the value both in the State array AND on the
entity :).
HTH
On Aug 21, 8:47 pm, Chris F <[email protected]> wrote:
> +1
>
> I've seen the same behaviour while debugging another problem.
> Immediately after running through my OnPreInsert code for all the
> entities being created, the OnPreUpdate is called for all the same
> entities.
>
> On Aug 11, 9:57 am, sirrocco <[email protected]> wrote:
>
> > If in an Event , onOnPreInsertI set a property ( RecordStamp) like
> > so :
>
> > var index = Array.FindIndex(names, n => n == "RecordStamp");
> > if (index == -1) return;
>
> > state[index] = DateTimeService.Now;
>
> > Can this cause an update after the insert ? The thing is that after
> > the app entersOnPreInsert, then on Commit it goes through the
> > OnPreUpdate.
>
> > The entity has an identity PrimaryKey.
> > The flow would be like this :
>
> > Entity e = new Entity()
> > session.Save(e) ->OnPreInsert
>
> > Commit -> OnPreUpdate
>
> > Any explanation of the behavior is much appreciated .
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---