First off, thanks for any help. I am using ria services to insert/update/delete entities and save a history of those operations. I want to perform the operation and save the history in ONE call to the service. Right now I am stuck on the insert because I need the new entities ID that is generated on the insert. I might be taking the wrong approach all together (but I hope not). I have overriden the submit method, and am trying to save a snapshot in the history table, I don't want to save a snapshot of the original version:
public override bool Submit( ChangeSet changeSet )
{
//SUBMIT FIRST SO THE OBJECT(S) HAVE AN ID
var success = base.Submit( changeSet );
if ( success )
foreach ( var changeSetEntry in changeSet.ChangeSetEntries )
{
if ( changeSetEntry.Entity is MyBusinessEntity )
{
var newBusinessEntity = (MyBusinessEntity) changeSetEntry.Entity;
RecordModifiedMyBusinessEntity( changeSetEntry.Operation, newBusinessEntity );
}
}
return success;
}
private void RecordModifiedMyBusinessEntity( DomainOperation operation, MyBusinessEntity newBusinessEntity )
{
var hist = new BusinessEntityHistory
{
ChangedBy = new AuthenticationService().GetUser().FriendlyName,
ChangedDate = DateTime.Now,
Operation = operation.ToString(),
BusinessEntityId = newBusinessEntity.Id,
Group = newBusinessEntity.Group,
Priority = newBusinessEntity.Priority,
....
};
InsertBusinessEntityHistory( hist );
//HERE IS WHERE I WANT TO CALL SUBMIT CHANGES AGAIN, BUT 1 - IT'S NOT IN THE CHANGESET,
//AND 2 - THE OBJECT I ALREADY INSERTED IS IN THE CHANGESET (SO IF I SUBMIT AGAIN, IT GETS
//INSERTED TWICE AND NO HISTORY IS SAVED. AND 3 - I CAN'T DO THE HISTORY BEFORE BECAUSE I DON'T
//HAVE THE ID, AND I DON'T WANT TO DO A MAX ID + 1 BECAUSE SOMEONE ELSE MIGHT BE
//INSERTING INTO THE SAME TABLE
}