I have a single table called customer with a PK field named CustomerID that is of type uniqueidentifier, Is RowGuid set to Yes, and a default value of (newid()). The following code seems to work fine, except the PK field contains all 0's after the save:
DataAccessAdapter da = new DataAccessAdapter();
CustomerEntity ce = new CustomerEntity();
ce.CustName = "AAAAA";
if (da.SaveEntity(ce) == false)
MessageBox.Show("Save Failed");
da.CloseConnection();
With that code, a record is added to the database. I figured since ce.CustomerID was not receiving the newly generated GUID, I needed to set the RefetchAfterSave flag. I changed the code as follows:
DataAccessAdapter da = new DataAccessAdapter();
CustomerEntity ce = new CustomerEntity();
ce.CustName = "AAAAA";
if (da.SaveEntity(ce,true) == false)
MessageBox.Show("Save Failed");
da.CloseConnection();
I now receive the following error:
"During a recursive save action an entity's save action failed. The entity which failed is enclosed."
For testing purposes, Customer is an independent table with no related tables. I'm pretty sure the error is related to the fact that since the PK doesn't have a value after the save, it cannot refetch the data from the DB.
Any ideas on how to get the newly generated GUID into CustomerEntity.CustomerID following a save?
Thanks.