Print Page | Close Window

getting error when calling save on clean(?) entity

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=1419
Printed Date: 22-Sep-2025 at 4:22am


Topic: getting error when calling save on clean(?) entity
Posted By: DanW
Subject: getting error when calling save on clean(?) entity
Date Posted: 10-Aug-2009 at 9:26am

Hello,  I have a routine that has a contact list, and can send an email from that list.  The list is a Sliverlight page, so I was using the AsyncSerialTask to handle the save & send calls, but I ran into an error when I am testing it from the actual silverlight page.. Here is the Async task,  

public void SendContact(DealConfContacts dealConfContacts, AsyncCompletedCallback<InvokeServerMethodEventArgs> callback)
        {
            IList<DealConfContacts> confContacts = new List<DealConfContacts>();
            confContacts.Add(dealConfContacts);
            SaveOptions saveOpt = new SaveOptions();
         
            var task1 = AsyncSerialTask.Create();
            task1.AddExceptionHandler(TestAsyncSerialTaskSerialExceptionHandler);
            var task2 = task1.AddAsyncSave(Manager, confContacts, saveOpt);

            // This was original save, switched to AddAsyncSave, both error in same place
            //var task2 = task1.AddAsyncAction<EntitySavedEventArgs>((serialArgs, callBackTo) => Manager.SaveChangesAsync(confContacts,callBackTo,null));
            var task3 = task2.AddAsyncAction<InvokeServerMethodEventArgs>((serialArgs, callBackTo) => DealConfContactsAsyncBehaviors.SendConfirmAsync("SYSTEM", Manager, dealConfContacts.DealConfirmation, dealConfContacts, "email", callBackTo));
            task3.Execute(callback);
        }

The error shows up here when the e.entities is accessed.  For the record, the entity may or may not have been dirty at this point, could that be the reason for the error? that the entity was clean when save was called? (I was hoping to write one stack that could save/create the entity, but if I need to differentiate before this point if it is not saved, please let me know.)

     void DomainModelEntityManager_Saved(object sender, EntitySavedEventArgs e)
        {
            if (!e.Cancelled)
            {
                if (e.Entities != null)
                {
                    foreach (object item in e.Entities)
                    {
                        var savedItem = item as ISaved;
                        if (savedItem != null)
                            savedItem.SavedHandler();
                    }
                }
            }
        }

Here is the error that I am seeing:

System.ArgumentNullException was unhandled by user code
  Message="Value cannot be null.\r\nParameter name: source"
  StackTrace:
       at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)
       at IdeaBlade.EntityModel.EntitySavedEventArgs.get_Entities()
       at GcsAg.DomainModel.DomainModelEntityManager.DomainModelEntityManager_Saved(Object sender, EntitySavedEventArgs e)
       at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
       at IdeaBlade.EntityModel.EntityManager.OnSaved(EntitySavedEventArgs args)
       at IdeaBlade.EntityModel.EntityManager.<SaveChangesAsyncCore>b__3c(EntitySavedEventArgs args)
       at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__1(Object x)
  InnerException:

thanks,
-DanW
 



Replies:
Posted By: DanW
Date Posted: 12-Aug-2009 at 5:50am
I have come up with a workaround of updating the "last updated" audit field that we have on all of our entities so that a save is forced, (which then causes an audit record to be generated in our audit log), so it's not a pretty solution, but I needed to get this process working.   
 
Thanks,
-Daniel


Posted By: kimj
Date Posted: 12-Aug-2009 at 9:34am
Hi Daniel, sorry to respond so late.   If you check e.IsCompleted or e.Result.SaveOperation first it will indicate the completion state and allow you to work around the problem with accessing e.Entities (which I think is a bug and will log).  You're right that the problem occurs when nothing was saved.



Print Page | Close Window