I have "solved" this using two different methods. The first re-uses the supertype record (Contact) and the second creates a new supertype record. Both methods work as written because all of the columns in the Client (subtype) table are nullable. If this is not your case, you will need to collect any required Client-specifc information prior to converting the Prospect to a Client.
Method 1
int ID = Prospect.ID;
DataAccessAdapter adapter = new DataAccessAdapter();
try {
ActionProcedures.Usp_ConvertProspectToClient(ID);
}
catch {
throw;
}
finally {
adapter.Dispose();
}
return new ClientService().GetClient(ID);
The stored procedure uses the ID parameter to insert a record into the Client table and delete a record from the Prospect table (inside a transaction, of course). The GetClient method of my ClientService simply reads the new Client using the same ID.
Method 2
// Create a new client
ClientEntity client = new ClientEntity();
// Copy the prospect's supertype information to the new client
_copyProspectInformationToClient(Prospect, client);
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.StartTransaction(IsolationLevel.Serializable, "ConvertProspectToClient");
try {
// Create the new client
adapter.SaveEntity(client, true, true);
// Delete the prospect
adapter.DeleteEntity(Prospect);
adapter.Commit();
}
catch {
adapter.Rollback();
throw;
}
finally {
adapter.Dispose();
}
return client;
private void _copyProspectInformationToClient(ProspectEntity prospect, ClientEntity client) {
foreach (IEntityField2 field in prospect.Fields) {
// Copy only the information from the prospect's supertype
if (field.ContainingObjectName == "ContactEntity" &&
field.Name != "ID") {
client.Fields[field.Name].CurrentValue = field.DbValue;
}
}
}
The code in _copyProspectInformationToClient() uses the field's ContainingObjectName property to determine which properties from the Prospect are in the supertype (ContactEntity) and copies those values to the Client.
The result of both methods is the same except that in Method 1 the supertype record remains the same whereas in Method 2 a new supertype record is created and the old is deleted so the ID is different.