How to save an entity that already exists?

Posts   
 
    
rekurtz
User
Posts: 4
Joined: 14-Sep-2009
# Posted on: 14-Sep-2009 20:46:33   

Entity.Save is what I need.

No concern about whether field values have changed or if the entity is in sync. I want to save the entity to persistent storage. The entity I want to save has not changed, but the persistent storage may have, the entity is the correct state to be saved and in essence it needs to update persistent storage to have the correct state.

How can this be accomplished?

Thank you!

rekurtz
User
Posts: 4
Joined: 14-Sep-2009
# Posted on: 14-Sep-2009 20:53:43   

More correctly said, how can an entity that hasn't been changed be saved?

Adapter.SaveEntity(entity) is the call, but if the entity hasn't had a value change, how can this be forced?

rekurtz
User
Posts: 4
Joined: 14-Sep-2009
# Posted on: 15-Sep-2009 00:48:25   

Looks like I found the answer. sunglasses

The process uses the entity.SaveFields and RollbackFields methods to capture and rollback the state.

foreach(entity ent in _entities)
{
    ent.RollbackFields("original");
    foreach(IEntityField2 field in ent.Fields)
    {
        if (field.IsReadOnly == false)
        {
            ent.Fields[field.Name].ForcedCurrentValueWrite(ent.Fields[field.Name].CurrentValue);
            ent.Fields[field.Name].IsChanged = true;
        }
    }
    ent.IsDirty = true;
}
_adapter.SaveEntityCollection(_entities);
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Sep-2009 06:35:51   

As a matter of fact, this line isn't necessary:

ent.Fields[field.Name].ForcedCurrentValueWrite(ent.Fields[field.Name].CurrentValue);
David Elizondo | LLBLGen Support Team
rekurtz
User
Posts: 4
Joined: 14-Sep-2009
# Posted on: 15-Sep-2009 17:37:14   

Thank you, daelmo, that worked.