Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Saving changes to related entity in PerformWork
 

Pages: 1
LLBLGen Pro Runtime Framework
Saving changes to related entity in PerformWork
Page:1/1 

  Print all messages in this thread  
Poster Message
tprohas
User



Location:
Tucson, AZ
Joined on:
23-Mar-2004 00:00:43
Posted:
257 posts
# Posted on: 23-Apr-2008 20:35:36.  
LLBLGen 2.5
Runtime: v2.0.50727
ASP.NET 2.0

I'm trying to make changes to a related entity when the root entity is being saved in the PerformWork event of the LLBLGenDataSource2 control. The code works but the update is never sent to the database. In the following code I'm also wondering why the IsDirty property on the visit request entity is never true.

Code:

protected void eventDetailsDS_PerformWork(object sender, PerformWorkEventArgs2 e)
{
    // LLBLGen really makes this kind of work a lot more fun.

    foreach (UnitOfWorkElement2 element in e.Uow.GetEntityElementsToUpdate())
    {
        ScheduledVisitEntity scheduledVisit = element.Entity as ScheduledVisitEntity;
        
        // Get visit requests related to this scheduled visit and update their properties.
        
        // First, let's see if we have a related visit request entity.
        if (scheduledVisit.VisitRequest.Count > 0)
        {
            // Get a reference to each visit request going to this event.
            foreach (VisitRequestEntity visitRequest in scheduledVisit.VisitRequest)
            {
                // Now find all the scheduled visit fields which have changed.
                foreach (IEntityField2 scheduledVisitField in scheduledVisit.Fields)
                {
                    if (scheduledVisitField.IsChanged)
                    {
                        // If this field exists in the visit request entity then update the value in visit request.
                        if (visitRequest.Fields[scheduledVisitField.Name] != null)
                        {
                            visitRequest.Fields[scheduledVisitField.Name].CurrentValue = scheduledVisit.Fields[scheduledVisitField.Name].CurrentValue;
                            // Will updating the visit request this way cause it to be saved with the scheduled visit?
                        }
                    }
                }

                if (visitRequest.IsDirty)
                {
                    // Why is the entity not dirty at this point?
                    e.Uow.AddForSave(visitRequest);
                }
            }
        }

        // We might want to check these two difference ways of updating the visit request and see which is more efficient.
        //ServiceManager.GetVisitProgramManager().CopyEventToRequest(scheduledVisit, visitRequest);
    }
    
    ServiceManager.GetPersistanceManager().UnitOfWorkCommit(e.Uow, true);
}


The UnitOfWork commit only saves the ScheduledVisitEntity. How can I make each of the related VisitRequestEntity's get saved as well?
Aaron Prohaska
http://www.verdesoft.com/
 
Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8060 posts
# Posted on: 24-Apr-2008 05:06:37.  
Try change this
Code:
visitRequest.Fields[scheduledVisitField.Name].CurrentValue = scheduledVisit.Fields[scheduledVisitField.Name].CurrentValue;


with this:
Code:
visitRequest.SetNewFieldValue(scheduledVisitField.Name, scheduledVisit.Fields[scheduledVisitField.Name].CurrentValue);


SetNewFieldValue fires validation/auditing routines and set the corresponding field flags.


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.