This is my product Class:
public class Product : XPLiteObject
{
public string productId {get;set;}
}
i use Gridview to control Data. When i delete a row with productId = "id-5";
gridview1.deleteSelectedRows();
then Add new row with productId = "id-5"; (same id i was deleted)
Finally i comit;
unitOfWork1.CommitChanges();
And exception recieved: A dupplicate key found !
It looks like a corresponding record was not removed from the database. There are three possible reasons:
If the GridView is bound to the XPCollection, make sure that the XPCollection.DeleteObjectOnRemove property is set to true. Otherwise, the GridView.DeleteSelectedRows method deletes object from the collection only;
If the GridView bound to the XPCollection through the UnitOfWork, you also need to execute the UnitOfWork.CommitChanges method after executing the GridView.DeleteSelectedRows. Otherwise, your changes will not be committed to the database;
If the Product class is decorated with the DeferredDeletionAttribute, deleting this object will set a corresponding boolean column value, but will not actually delete the record from the database. If this is the case, there are four ways to resolve the problem:
Disable the Deferred Deletion feature at this class by setting the DeferredDeletionAttribute.Enabled property to false;
Make sure that objects you are adding are always have a unique value in the key property;
Instead of creating a new object with the key that is already used, restore the deleted one: How to restore deleted objects (records)
You can physically remove from the database records being marked deleted. Use the Session.PurgeDeletedRecords method for this purpose.