Print Page | Close Window

Saved Event Questions

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1505
Printed Date: 25-Mar-2025 at 1:43pm


Topic: Saved Event Questions
Posted By: skingaby
Subject: Saved Event Questions
Date Posted: 01-Oct-2009 at 6:18am
I have added a Saved event handler to the DomainModelEntityManager:

void DomainModelEntityManager_Saved(object sender, EntitySavedEventArgs e)
{
    DebugFns.WriteLine("DomainModelEntityManager_Saved: Enter");
    if (e.IsCompleted)
    {
        if (!e.Cancelled)
        {
            if (e.Entities != null)
            {
               foreach (object item in e.Entities)
               {
                    DoMoreStuff();
               }
            }
        }
    }
}


1) What is the purpose of the e.IsCompleted? It seems to be false most of the time. Why is the Saved event firing before the Save is marked as complete? The save has succeeded and the data is in the database. Should we use e.Result.Ok instead?

2) Which canceled flag should we be using: e.Cancelled or e.Result.WasCancelled? What's the difference?

Thanks, Simon



Replies:
Posted By: kimj
Date Posted: 02-Oct-2009 at 10:07am
The problem with e.IsCompleted being false is a bug.  The Saved event does fire when the save is truly complete, we've just forgotten to set that flag (it is finally set by the time the callback passed to the SaveChangesAsync is called).   We'll get this fixed.   You can use e.Result.OK, but you should check either e.Error or e.Exception first (they'll return the same thing, e.Exception is typed as an EntityManagerSaveException).  e.Result.OK will be true if a) the save was not cancelled and b) an error occurred which was handled by an EntityServerError handler.
 
e.Cancelled and e.Result.WasCancelled will always be the same.   Our confusing API came about because we decided to make the EntitySavedEventArgs do double duty -- these args extend System.ComponentnModel.AsyncCompletedEventArgs yet are used both for the Saved event, which is raised for sync and async saves; and as the arguments to the async callback.   The AsyncCompletedEventArgs defines a Cancelled property, while our DevForce SaveResult uses the WasCancelled flag.  A SaveResult is returned by a synchronous SaveChanges(), and is also the type of the e.Result here.   We'll see if we can clean up the API and/or documentation a bit. :) 


Posted By: skingaby
Date Posted: 02-Oct-2009 at 12:52pm
I see. Thank you for the explanation.



Print Page | Close Window