PerformWork Common Code

Posts   
 
    
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Jul-2007 17:02:02   

I am using the PerformWork event handler to pass delete/insert/update requests back to the BL from the PL (through Web Services). At first, I was thinking I could pass the UOW object - since it contains a full collection of the chnages. But, that doesn't appear to be supported - so I moved to the following basic approach:

protected void dsEmployees_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
        {
            EmployeeService.Employee ws = new EmployeeService.Employee();

            foreach (UnitOfWorkElement2 element in e.Uow.GetEntityElementsToDelete()) 
            {
                ws.Delete(((EmployeeEntity)element.Entity).Empid);
            }
            foreach (UnitOfWorkElement2 element in e.Uow.GetEntityElementsToInsert())
            {
                ws.Update((EmployeeEntity)element.Entity);
            }
            foreach (UnitOfWorkElement2 element in e.Uow.GetEntityElementsToUpdate())
            {
                ws.Update((EmployeeEntity)element.Entity);
            }
        }

My question is: Is there a more elegent way that is built into LLBLGen to do this? I would like to avoid:

  • repeating this block of code for every datasource
  • making repetitive calls to the underlying Web Service (I'd rather one single call) Thoughts, anyone?
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 12-Jul-2007 10:41:13   

Are you using an Ajax-style grid for example? Or the gridview? The thing is that unless a grid is doing edits on the client (in the browser), the unitofwork will always contain just 1 entity, as the edit action (or delete action) will always cause a postback and thus a PerformWork call.

In that case, you then can just send the entity over the wire to the particular method.

UoW isn't serializable to Xml, as we want to encourage message-based webservices instead of REST based webservices.

Frans Bouma | Lead developer LLBLGen Pro