Would it be possible to call SaveChanges in an async way with a ExecuteCompleted event?

Answered Would it be possible to call SaveChanges in an async way with a ExecuteCompleted event?

  • Sonntag, 5. August 2012 07:39
     
     

    In the Query pipeline, it's pretty simple to retrieve a records explicitely async with an ExecuteCompleted event returning the result.

    I just wrote a small blog post on how to do this: http://blog.pragmaswitch.com/?p=375

    Now, I'm wondering if the same could be applied in the Save pipeline. So, calling the Savechanges in a async way on the dataworkspace and getting back something like a SaveChangesCompleted event.


    paul van bladel


Alle Antworten

  • Dienstag, 7. August 2012 06:18
     
      Enthält Code

    No suggestions?

    So, I would like something like this (just pseudo-code)

    var submitOperation = ...DataWorkspace.CreateSubmitOperation(...°
     
    submitOperation.ExecuteCompleted += new EventHandler<ExecuteCompletedEventArgs>((s, e) =>
                {
                    //continue after saving...
                 });
    submitOperation.ExecuteAsync();


    paul van bladel

  • Mittwoch, 8. August 2012 00:54
    Moderator
     
     Beantwortet Enthält Code

    You're close, but what you need to do is get the SaveChanges method off of the details of the data service that you want to save and create an invocation of that method:

    partial void SaveAsync_Execute()
    {
        ISubmitOperationInvocation saveChangesInvocation = this.DataWorkspace.ApplicationData.Details.Methods.SaveChanges.CreateInvocation(new object[] { });
        saveChangesInvocation.ExecuteCompleted += this.SaveChangesInvocation_ExecuteCompleted;
        saveChangesInvocation.ExecuteAsync();
    }
    
    void SaveChangesInvocation_ExecuteCompleted(object sender, Microsoft.LightSwitch.ExecuteCompletedEventArgs e)
    {
                
    }


    Justin Anderson, LightSwitch Development Team

  • Mittwoch, 8. August 2012 07:23
     
     

    Hi Justin,

    I just knew you would be the person to provide the missing link :)

    Many thanks !

    paul.


    paul van bladel