// other methods are convenience wrappers around this.
        private static T UpdateGraph <T>(this DbContext context, T entity, Expression <Func <IUpdateConfiguration <T>, object> > mapping,
                                         string mappingScheme, UpdateParams updateParams) where T : class
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var entityManager = new EntityManager(context);
            var queryLoader   = new QueryLoader(context, entityManager);
            var register      = new AggregateRegister(new CacheProvider());

            var root   = GetRootNode(mapping, mappingScheme, register);
            var differ = new GraphDiffer <T>(context, queryLoader, entityManager, root);

            var queryMode = updateParams != null ? updateParams.QueryMode : QueryMode.SingleQuery;

            return(differ.Merge(entity, queryMode));
        }
 /// <summary>
 /// Merges a graph of entities with the data store.
 /// </summary>
 /// <typeparam name="T">The type of the root entity</typeparam>
 /// <param name="context">The database context to attach / detach.</param>
 /// <param name="entity">The root entity.</param>
 /// <param name="mappingScheme">Pre-configured mappingScheme</param>
 /// <param name="updateParams">Update configuration overrides</param>
 /// <returns>The attached entity graph</returns>
 public static T UpdateGraph <T>(this DbContext context, T entity, string mappingScheme, UpdateParams updateParams = null) where T : class
 {
     return(UpdateGraph(context, entity, null, mappingScheme, updateParams));
 }
 /// <summary>
 /// Merges a graph of entities with the data store.
 /// </summary>
 /// <typeparam name="T">The type of the root entity</typeparam>
 /// <param name="context">The database context to attach / detach.</param>
 /// <param name="entity">The root entity.</param>
 /// <param name="updateParams">Update configuration overrides</param>
 /// <returns>The attached entity graph</returns>
 public static T UpdateGraph <T>(this DbContext context, T entity, UpdateParams updateParams = null) where T : class
 {
     return(UpdateGraph(context, entity, null, null, updateParams));
 }
 /// <summary>
 /// Merges a graph of entities with the data store.
 /// </summary>
 /// <typeparam name="T">The type of the root entity</typeparam>
 /// <param name="context">The database context to attach / detach.</param>
 /// <param name="entity">The root entity.</param>
 /// <param name="mapping">The mapping configuration to define the bounds of the graph</param>
 /// <param name="updateParams">Update configuration overrides</param>
 /// <returns>The attached entity graph</returns>
 public static T UpdateGraph <T>(this DbContext context, T entity, Expression <Func <IUpdateConfiguration <T>, object> > mapping, UpdateParams updateParams = null) where T : class
 {
     return(UpdateGraph(context, entity, mapping, null, updateParams));
 }