ChangeSet and SubmitChanges issue RRS feed

  • Question

  • Hi

    I am working on Logging idea ( to store all the user's actions from insert, delete, update ) and I am facing problem in getting the Changes in the DataContext, in the delete list ( all the foreign keys are null or 0 )

    here is my method...

    I made partial class for my DataContext object and I override the SubmitChanges method and I created event before SubmitChanges and event After SubmitChanges

    in Before Submit Changes event

    I stored all the changes inside 3 lists ( inserts , deletes, updates)

    and in after Submit Changes

    I was storing the lists in the LogDB

    everything works fine for my application except ( Delete data are not complete because the foreign keys are 0, and in this way I am not able to know on which object the changed happened), this because when I call DeleteOnSubmit , DataContext sets the references to null and the foreign id's to 0 though

    is there any way to know these data?


    thanks in advance

    Thursday, May 20, 2010 10:18 AM


  • Hi again guys

    I solved this issue by using this method "GetOriginalEntityState"


    here the code

    if your DataCotext instance is called context and your table called TCustomer

    then you do this

    ChangeSet changeSet=context.GetChangeSet();
    foreach(object item in changeSet.Deletes)
    TCustomer customer=context.TCustomers.GetOriginalEntityState(item as TCustomer);
    //here you will get all the foreign keys values also and you can proceed

    thanks for all people who tried to help me

    Best regards

    • Marked as answer by Hadi2008 Thursday, May 20, 2010 12:53 PM
    Thursday, May 20, 2010 12:16 PM