This has probably been asked before, but i couldn't find a existing
post explaining it.

Currently we have a web service which is accessed by our client
application in order to talk to the database.

The asmx WebService has web methods similar to this (this is a
simplification):
NOTE: Thingy is an AR Model

[WebMethod]
public Thingy GetThingy(int id)
{
    return ActiveRecordMediator<Thingy>.FindByPrimaryKey(id);
}


[WebMethod]
public Thingy UpdateThingy(Thingy thingy)
{
    ActiveRecordMediator<Thingy>.Update(thingy);
    return thingy;
}


there is also some other code in another part of the code which
basically creates a SessionScope for each web request.

Now, this code seemed to work at first (updated the DB appropriately).
However then i added an IPreUpdateEventListener which is basically
used to log which properties on each object where changed.

The problem that i had is in the OnPostUpdate(PostUpdateEvent
postUpdateEvent) method of my EventListener postUpdateEvent.OldState
is always null.

After some research and asking questions i have worked out that this
is because when calling the Update web method, the 'thingy' that is
passed in is a detatched model (not attatched to the current session)
so AR has no way of knowing the previous values of the Thingy (which
makes sense).

however i need to find some way of updating the thingy in the
database, but still being able to know which properties where changed
in that row of the database.

I understand that i may have to do a FindByPrimaryKey before i do the
update so that AR can know the state of the object before the update.
but i couldn't get it to work by just doing a find and then an update
on the object passed in as the parameter.

p.s. i realize i could probably get it to work by doing a Find, then
updating the returned object manually from the object passed in (and
then saving the object returned from the find)... but i don't want to
have to update the object manually, because this is going to have to
be done for many-many different models, so i need a method that is not
fragile and can be done pretty simply for any type

thanks in advance

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to