Entity not being saved

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 17-Oct-2005 20:42:52   

I have two methods that save entity data. One method works and the other does not work. Can anyone tell me why? I have set a break point in the non working method to make sure that the primary key for the CustomerOrderEntity and the BuildEntity is correct so I know that the PK values are correct.

Working method:

private void employeeGrid_RecordUpdated(object sender, RowActionEventArgs e)
{
    GridEXRow row = e.Row;
    int employeeId = Convert.ToInt32(row.DataKeyValue);

    EmployeeEntity employee = new EmployeeEntity(employeeId);
    employee.IsNew = false;
    employee.Person = new PersonEntity(employeeId);
    employee.Person.IsNew = false;

    foreach(GridEXCell cell in row.Cells)
    {
        if ( cell.DataChanged )
        {
            string fieldName = cell.Column.DataMember;
            object cellValue = cell.Value;
            if ( cellValue == null )
                cellValue = string.Empty;

            if ( Enum.IsDefined(typeof(EmployeeFieldIndex), fieldName) )
                employee.SetNewFieldValue(fieldName, cellValue);

            else
                employee.Person.SetNewFieldValue(fieldName, cellValue);
        }
    }
    // This won't add duplicates even though its executed
    // on the same item multiple times.
    ServiceFactory.GetPersistanceManager().SaveEntity(employee);
}

Non-working method:

private void ordersGrid_RecordUpdated(object sender, RowActionEventArgs e)
{
    GridEXRow row = e.Row;
    int rowIndex = row.RowIndex;

    CustomerOrderEntity order = (CustomerOrderEntity)this.orders[rowIndex];
    CustomerOrderEntity updateOrder = new CustomerOrderEntity((int)row.DataKeyValue);
    updateOrder.IsNew = false;
    updateOrder.Build = new BuildEntity(order.BuildID);
    updateOrder.Build.IsNew = false;

    foreach(GridEXCell cell in row.Cells)
    {
        object cellValue;
        string dataMember;

        if ( cell.DataChanged )
        {
            dataMember = cell.Column.DataMember;
            cellValue = cell.Value;
            
            if ( cellValue == null )
                cellValue = string.Empty;

            if ( Enum.IsDefined(typeof(CustomerOrderFieldIndex), dataMember) )
                updateOrder.SetNewFieldValue(dataMember, cellValue);
            else
                updateOrder.Build.SetNewFieldValue(dataMember, cellValue);
        }
    }
    ServiceFactory.GetPersistanceManager().SaveEntity(order);
}
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 17-Oct-2005 20:49:31   

Yes, of course the minute that I ask for help I figure out the problem on my own. I wasn't passing the correct object instance into the save method. Thanks for listening simple_smile