/// <summary>
        /// Save (insert/update) a ControlledUpdateThing into the store
        /// </summary>
        /// <param name="entitiesBeingHandled">Entities already being saved further up the save stack</param>
        /// <param name="controlledUpdateThings">The ControlledUpdateThings to save</param>
        /// <param name="toSave">Entity types to cascade to, if they are loaded</param>
        internal void Save(List <Entity> entitiesBeingHandled, Flags toSave, params ControlledUpdateThing[] controlledUpdateThings)
        {
            if (controlledUpdateThings == null)
            {
                throw new ArgumentNullException("controlledUpdateThings");
            }
            Log("Save", controlledUpdateThings.Select <ControlledUpdateThing, int>(entity => entity.Identity).ToArray <int>(), EntityType.None);

            // Copy the list of entities being handled, and add this new set of entities to it.
            // We're handling those now.
            List <Entity> entitiesNowBeingHandled = new List <Entity>(entitiesBeingHandled);

            entitiesNowBeingHandled.AddRange(controlledUpdateThings);

            // Loop over each entity and save it.
            foreach (ControlledUpdateThing controlledUpdateThing in controlledUpdateThings)
            {
                using (PebblecodeUpdateContexts.PebbleAdmin(controlledUpdateThing)) {
                    // Already being saved higher up the stack?
                    if (entitiesBeingHandled.ContainsEntity(controlledUpdateThing))
                    {
                        continue;
                    }

                    // Allow derived/partial class to do extra work
                    OnBeforeSaveEntity(controlledUpdateThing);

                    bool saved = false;

                    try
                    {
                        // Save the entity
                        if (controlledUpdateThing.IsNew)
                        {
                            this.Mapper.Insert("InsertControlledUpdateThing", controlledUpdateThing);
                            saved = true;
                        }
                        else if (controlledUpdateThing.IsChanged)
                        {
                            if (this.Mapper.Update("UpdateControlledUpdateThing", controlledUpdateThing) != 1)
                            {
                                ThrowControlledUpdateThingEntityException(controlledUpdateThing.Identity);
                            }
                            saved = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw EntityLogger.WriteUnexpectedException(
                                  ex,
                                  "Failed to insert/update Entity",
                                  Category.EntityFramework,
                                  controlledUpdateThing);
                    }

                    // Post save protocol
                    if (saved)
                    {
                        // Allow derived/partial class to do extra work
                        OnAfterSaveEntity(controlledUpdateThing);
                        try
                        {
                            VersionedEntityInfo versionInfo = this.Mapper.QueryForObject <VersionedEntityInfo>(
                                "SelectControlledUpdateThingVersionInfo",
                                controlledUpdateThing.Identity);
                            controlledUpdateThing.Reset(versionInfo);
                        }
                        catch (Exception ex)
                        {
                            throw EntityLogger.WriteUnexpectedException(
                                      ex,
                                      "Failed to reset version information",
                                      Category.EntityFramework,
                                      controlledUpdateThing);
                        }

                        //The insert/update will have resulted in a new database_update row, inform interested parties
                        RaiseModelChanged();
                    }
                }
            }
        }