ForceUpdate on a child object?

ForceUpdate on a child object?

Old forum URL: forums.lhotka.net/forums/t/4720.aspx


reagan123 posted on Monday, April 21, 2008

Is there a way to mark a child object IsDirty in order to force it to save?

Thanks!

RockfordLhotka replied on Monday, April 21, 2008

What is your scenario? You somehow have a child object that you haven't changed, but you want it to do an update into the database anyway?

reagan123 replied on Monday, April 21, 2008

Yes... We have a scenarion where I fetch all of my objects from a database server and serialize them to a file.  This file is then moved to a disconnected machine that has a blank version of the database on it.  I then deserialize the file and save all of our objects to the blank database.

My issue is that I can force the parent to be dirty, but when I loop through my child collection the IsDirty flag is clean since I haven't changed any data.  This means all of my parent objects make it into the database, but no kids/grandkids.

Hope that made sense.  The biggest issue is that we had an incomplete scope of the software and we are trying to make due with the design we have until we can get some time. :(

I appreciate the response and any further help.

Fintanv replied on Monday, April 21, 2008

In cases where I have had to to this I took the route of creating an internally scoped method on the child class that simply calls MarkDirty().  Your parent then has the ability to loop through the children and invoke the method as needed.  (In your scenario the child would have to do the same thing for its children etc etc.)

Maybe not particularly elegant, but it got the job done.

-- Fintan

RockfordLhotka replied on Monday, April 21, 2008

That’s what I was going to recommend J

 

Rocky

 

From: Fintanv [mailto:cslanet@lhotka.net]
Sent: Monday, April 21, 2008 10:03 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] ForceUpdate on a child object?

 

In cases where I have had to to this I took the route of creating an internally scoped method on the child class that simply calles MarkDirty().  Your parent then has the ability to loop through the children and invoke the method as needed.  (In your scenario the child would have to do the same thing for its children etc etc.)

Maybe not particularly elegant, but it got the job done.

-- Fintan



reagan123 replied on Monday, April 21, 2008

Thank for the responses from both of you.

That seems to be a perfect solution to my issue.

Copyright (c) Marimer LLC