LLBLGenProDataSource does not update Entity to Insert after an exception

Posts   
 
    
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 03-Jan-2009 20:54:09   

I have a web page with a LLBLGenProDataSource (SelfServicing) with LivePersistence=false databound to a FormView. When inserting a new entity and an exception occurs (due to entity Validator or any other reason) in PerformWork event, it is caught in ItemInserted event of the FormView so I display an error message in the form while preserving the form values. When the form is resubmitted the form changes are not updated to the UnitOfWork and the old values are persisted.

To reproduce this use the sample project WebDataBinding_06062008, SelfServicingWebApp2, Employee.aspx page. In EmployeeDetailsDS_PerformWork throw a generic exception before e.Uow.Commit line and add the following to the EmployeeFormView_ItemInserted:


            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;

                // add a label to the FormView to display the exception message
                //Label lblException = frmEditCreditCard.FindControl("lblException") as Label;

                //if (lblException != null)
                //{
                //  lblException.Text = e.Exception.Message;
                //}
                
            }

Set a break point at line 188, SetPicture(entityToInsert); and try to submit a new Employee. After the first try make a change to the value of one of the textboxes and resubmit again. Once the debugger stops at the breakpoint check the value of the changed property of the entityToInsert and will notice it had not been changed between submits.

Everything works as expected when updating existing entities.

Thank you,

Val

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Jan-2009 21:13:33   

Hi Val,

That behavior is because the involved entity (first save attempt) fails due to the exception but the entity wasn't removed. So, at the second save attempt a new entity is added to the bucket. If you check, you should notice that inserteItems.Count is 2.

You have to clean the contents of the UOW if an exception is caught:

catch(Exception ex)
{
     e.Uow.Reset();
     ...
}
David Elizondo | LLBLGen Support Team
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 04-Jan-2009 22:07:22   

David

Thank you. That worked.

Val

P.S. Outstanding customer service. Keep up the good work.