/// <summary> /// Extension method to perform sync/async version of DataServiceContext.SaveChanges dynamically /// </summary> /// <param name="context">The context to save changes on</param> /// <param name="continuation">The asynchronous continuation</param> /// <param name="async">A value indicating whether or not to use async API</param> /// <param name="options">The save changes options to use or null to use the overload without options</param> /// <param name="onCompletion">A callback for when the call completes</param> public static void SaveChanges(this WrappedDataServiceContext context, IAsyncContinuation continuation, bool async, SaveChangesOptions?options, Action <WrappedDataServiceResponse> onCompletion) { ExceptionUtilities.CheckArgumentNotNull(context, "context"); if (options == null) { AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedDataServiceResponse>(continuation, async, () => context.SaveChanges(), c => context.BeginSaveChanges(c, null), r => context.EndSaveChanges(r), onCompletion); } else { var wrappedEnum = context.Scope.Wrap <WrappedEnum>(options.Value.ToProductEnum()); AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedDataServiceResponse>(continuation, async, () => context.SaveChanges(wrappedEnum), c => context.BeginSaveChanges(wrappedEnum, c, null), r => context.EndSaveChanges(r), onCompletion); } }