/// <summary> /// <para>Merge changes from a one or more updated entities into original entities.</para> /// <para>First call GetChanges on the change tracker, passing changes to a service update operation.</para> /// <para>Then call MergeChanges, passing one or more updated entities from the service update operation.</para> /// <para>Properties on original entities will be set to those from updated entities.</para> /// <code> /// // Usage: /// // Start change-tracking originalEntity (new or retrieved from service) /// var changeTracker = new ChangeTrackingCollection(originalEntity); /// /// // Make changes to originalEntity, including reference and child entities /// /// // Get changes /// var changedEntity = changeTracker.GetChanges().SingleOrDefault(); /// /// // Pass changes to service update operation /// var updatedEntity = service.Update(changedEntity); /// /// // Merge updates from updated entity back into the original entity /// changeTracker.MergeChanges(updatedEntity); /// </code> /// </summary> /// <typeparam name="TEntity">Trackable entity type</typeparam> /// <param name="changeTracker">Change tracker used to track changes on original entities</param> /// <param name="updatedItems">One or more entities updated with changes from a service update operation</param> /// <exception cref="ArgumentException"> /// <para>Entity must implement IEquatable(TEntity)</para> /// <para>Update Trackable Entities Visual Studio Extension to v 2.0 or later, then re-generate client entities.</para> /// </exception> public static void MergeChanges <TEntity>(this ChangeTrackingCollection <TEntity> changeTracker, params TEntity[] updatedItems) where TEntity : class, ITrackable, IIdentifiable, INotifyPropertyChanged { // Check for no items if (updatedItems == null) { throw new ArgumentNullException("updatedItems"); } // Recursively set tracking state for child collections changeTracker.MergeChanges(updatedItems, null); }
public static ChangeTrackingCollection <TEntity> GetChanges(ChangeTrackingCollection <TEntity> source) { var helper = new CloneChangesHelper(); var wrapper = new Wrapper() { Result = source }; // Inspect the graph and collect entityChangedInfos helper.GetChanges(Enumerable.Repeat(wrapper, 1)).ToList(); // Clone only changed items var clone = TrackableExtensions.CloneObject(wrapper, helper); return(clone.Result); }