Suppose I have the following table:
CREATE TABLE EXAMPLETABLE (
ID NUMBER(10,0) NOT NULL,
DELETIONDATE DATE,
NAME VARCHAR2(100 CHAR) NOT NULL,
UNIQUE (DELETIONDATE, NAME));
How to soft delete an item from a WPF DataGrid? Soft deletion is the operation below:
UPDATE EXAMPLETABLE
SET DELETIONDATE = NOW()
WHERE ID = SOMEID;
Should I handle the KeyPress event?
In the form I have a Save button, should I do some treatment before calling entities.SaveChanges()?
You havn’t provided a lot of information about how you use the datagrid so I will have to make some assumptions.
If you want the “soft deletion” to happen when the user deletes a row from the datagrid you need to enable deletion of rows. You do that by setting
CanUserDeleteRowstoTrue.I assume that you are using some kind of databinding to bind the rows in the datagrid. When a row is deleted the underlying object in
ItemsSourceis removed from that collection. If you use a collection implementingINotifyCollectionChanged(likeObservableCollection) an event is fired when that happens.You can listen to that event and modify the underlying model object accordingly by setting
DeletionDatetoDateTime.Now. You will then have to callentities.SaveChanges()to push that change to the database.