Пример #1
0
        public List <UpdateDefinition <BsonDocument> > BuildUpdatesForSave(
            UpdateDefinition <BsonDocument> update, TrackableSetTracker <T> tracker, params object[] keyValues)
        {
            var updates      = new List <UpdateDefinition <BsonDocument> >();
            var keyNamespace = DocumentHelper.ToDotPath(keyValues);

            if (tracker.AddValues.Any())
            {
                updates.Add(update == null
                    ? Builders <BsonDocument> .Update.AddToSetEach(keyNamespace, tracker.AddValues)
                    : update.AddToSetEach(keyNamespace, tracker.AddValues));
                update = null;
            }

            if (tracker.RemoveValues.Any())
            {
                updates.Add(update == null
                    ? Builders <BsonDocument> .Update.PullAll(keyNamespace, tracker.RemoveValues)
                    : update.PullAll(keyNamespace, tracker.RemoveValues));
                update = null;
            }

            if (update != null)
            {
                updates.Add(update);
            }

            return(updates);
        }