Update primary key of entity

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 08-Jul-2005 21:43:55   

I have a table a EmployeeManufacturer that is used to associate an employee to a manufacturer in the system. The table has three fields all primary key fields (EmployeeID, ManufacturerID, RidingStyleID). I have inserted some rows into the table using the EmployeeManufacturerEntity which works fine. Now I am trying to update the ManufacturerID for one of the employees and it doesn't work. The only thing I can figure is that because the ManufacturerID that I am trying to change is part of the primary key it won't work. I am not getting any errors and watching what happends using sql profiler only shows me that the update statement is never executed. At the moment I don't have any idea why I can't make an update of a row work.

Also, if I debug the employeeManufacturer instance where its being saved I can see that the FieldChanged property is not set to true for the ManufacturerID which I have changed.

Here is the code that I use for the update. This is using a Janus Systems asp.net GridEX control.


private void employeeManufacturerGrid_RecordUpdated(object sender, RowActionEventArgs e)
{
    GridEXRow row = e.Row;
    int employeeID = (int)row.CompositeDataKeyValues[0];
    int manufacturerID = (int)row.CompositeDataKeyValues[1];
    string styleCode = (string)row.CompositeDataKeyValues[2];
    EmployeeManufacturerEntity employeeManufacturer = new EmployeeManufacturerEntity(employeeID, manufacturerID, styleCode);
    employeeManufacturer.IsNew = false;

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

            employeeManufacturer.SetNewFieldValue(fieldName, cellValue);
        }
    }
    ServiceFactory.GetPersistanceManager().SaveEntity(employeeManufacturer);
}

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 09-Jul-2005 16:54:39   

Altering a PK field should work in the way you do it, the only way I can imagine that the PK field isn't set to a value is because of the fact the value isn't different from the previous value or a validator rejects the value.

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 13-Aug-2005 02:02:39   

Otis wrote:

Altering a PK field should work in the way you do it, the only way I can imagine that the PK field isn't set to a value is because of the fact the value isn't different from the previous value or a validator rejects the value.

I still have not been able to make this update work. I just found another article where you state that a primary key can't be updated and this is by design. Does this apply to my issue?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 13-Aug-2005 11:00:36   

that previous message was probably from a date when it wasn't implemented, I later on implemented a way to update a PK, though it's not recursive, e.g. you can't use it in a recursive save.

Frans Bouma | Lead developer LLBLGen Pro