Last post Aug 28, 2009 10:28 AM by prasadrmarathe
Aug 20, 2009 01:50 AM|prasadrmarathe|LINK
In my dynamic data website i wish to update the 'IsDeleted' flag rather than deleting a record.(Soft Delete)
So under my domain service class in my public
contact) method i have called the following code
Contact originalContact1 = this.ChangeSet.GetOriginal(contact);
However i always get the originalContact1 as NULL.
Does the this.ChangeSet.GetOriginal(contact); method doesnt work under the delete() method, does it only work under the Update() method.
Please suggest, how can i perform this task.
Aug 20, 2009 04:55 AM|DaveRuss|LINK
I did this by modifying the List.aspx page:
1. Remove the autogenerated delete button from the grid
2. Add your own "Delete" button to a grid column and assign it a Command.
<asp:Button runat="server" ID="btnDelete" CommandName="TryDelete" CommandArgument="<%# GetPrimaryKeyValue() %>"/>
Protected Function GetPrimaryKeyValue() As String
Dim t = MetaModel.Default.GetTable(Page.GetDataItem.GetType)
3. Capture your command on the server in the GridView1_RowCommand event and do whatever-updates-you-like to pretend it's a "delete" function. In this event, GridView1.DataSourceObject will give you the current entity and you can call the GetTable method
on it to get the MetaTable. e.CommandArgument gives you the "ID" of the applicable row in the grid being deleted.
Aug 28, 2009 08:30 AM|prasadrmarathe|LINK
Thanks for your reply.
I tried your solution, i could get the metatable and the primary key value in the GridView1_RowCommand event however now how could i set my contact.IsDeleted= true;
I am not able to set this for the record for which i have the primary key value with me .
I have following code to get the metatable in GridView1_RowCommand event :
DynamicDataRouteHandler.GetRequestMetaTable(Context).Model.TryGetTable("Contact", out contactMetatable);
Aug 28, 2009 08:56 AM|DaveRuss|LINK
OK. A bit more detail.
Private Sub SetPropertyValue(ByVal obj As Object, ByVal prop As String, ByVal val As Object)
Dim MyBindingAttr = BindingFlags.GetField Or BindingFlags.GetProperty Or BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.Static
Dim pi As PropertyInfo = obj.GetType.GetProperty(prop, MyBindingAttr)
If pi IsNot Nothing Then
pi.SetValue(obj, val, MyBindingAttr, Nothing, Nothing, Nothing)
Aug 28, 2009 09:18 AM|prasadrmarathe|LINK
Thanks for the reply.
Can we do the same at the metadat class level, rather than using reflection on the page level.
Is there any other way to do it like below in the update(Contact contact) method of metadata class,
Just to make it simple and generic...
Aug 28, 2009 09:29 AM|DaveRuss|LINK
Certainly worth investigating. ChangeSet and AttachAsModified aren't available to me using the DataServicesDataContext, but if they're available using EntityDataContext or L2S then go for it!
Aug 28, 2009 10:28 AM|prasadrmarathe|LINK
Was able to achieve this by cloning the object and keeping it as my original object.
Thanks for your support.