Actually, in my code I was just updating the State array.
Apparently that was the reason I was also getting the update.

When I update the State and the Entity - for me , the update doesn't
happen .

PS: I found your question in another thread bellow and saw that you
are doing this already .

So I guess I'm not much help :(

On Aug 21, 9:54 pm, Chris F <[email protected]> wrote:
> Indeed, I did run the code with the commented out line, and the
> OnPreUpdate still gets called. I even commented out the entity state
> update (separately), and still OnPreUpdate gets called.
>
> So I'm still not understanding why this happens.
>
> On Aug 21, 2:50 pm, Chris F <[email protected]> wrote:
>
> > "This doesn't generate the extra update. I just couldn't see the
> > difference." ?? Did you mean DOES generate?
>
> > I wasn't able to discern what you meant in your last post. I totally
> > get that you have to perform the Set on the @event.State, AND that you
> > have to update the entity:
>
> > (1) Set(@event.Persister, @event.State, "CreatedDate", createdDate);
> > (2) entity.CreatedDate = createdDate;
>
> > But are you saying that (2) causes the OnPreUpdate to get called?
>
> > I guess I could get that answer by commenting out the
> > entity.CreatedDate = createdDate and see if the OnPreUpdate gets
> > called.
>
> > Sorry for asking for further clarification.
>
> > - Chris
>
> > On Aug 21, 2:36 pm, sirrocco <[email protected]> wrote:
>
> > > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to