New Posts New Posts RSS Feed: Saved Event Questions
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Saved Event Questions

 Post Reply Post Reply
Author
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Topic: Saved Event Questions
    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

Edited by skingaby - 01-Oct-2009 at 6:19am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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. :) 
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 02-Oct-2009 at 12:52pm
I see. Thank you for the explanation.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down