public static ToDotPathWithTrailer ( IEnumerable | ||
keys | IEnumerable | |
return | string |
public UpdateDefinition <BsonDocument> BuildUpdatesForSave(UpdateDefinition <BsonDocument> update, TrackableDictionaryTracker <TKey, TValue> tracker, params object[] keyValues) { var keyNamespace = DocumentHelper.ToDotPathWithTrailer(keyValues); foreach (var change in tracker.ChangeMap) { switch (change.Value.Operation) { case TrackableDictionaryOperation.Add: case TrackableDictionaryOperation.Modify: update = update == null ? Builders <BsonDocument> .Update.Set(keyNamespace + change.Key, change.Value.NewValue) : update.Set(keyNamespace + change.Key, change.Value.NewValue); break; case TrackableDictionaryOperation.Remove: update = update == null ? Builders <BsonDocument> .Update.Unset(keyNamespace + change.Key) : update.Unset(keyNamespace + change.Key); break; } } return(update); }
public UpdateDefinition <BsonDocument> BuildUpdatesForSave( UpdateDefinition <BsonDocument> update, TrackablePocoTracker <T> tracker, params object[] keyValues) { var keyNamespace = DocumentHelper.ToDotPathWithTrailer(keyValues); // mimic BsonClassMapSerializer.Serialize to serialize changed value correctly. // build bson elements containing set field values var setDocument = new BsonDocument(); var setBsonWriter = new BsonDocumentWriter(setDocument); var setContext = BsonSerializationContext.CreateRoot(setBsonWriter); setBsonWriter.WriteStartDocument(); foreach (var change in tracker.ChangeMap) { if (change.Value.NewValue != null) { BsonMemberMap memberMap; if (_propertyToMemberMap.TryGetValue(change.Key, out memberMap) == false) { continue; } setBsonWriter.WriteName(memberMap.ElementName); memberMap.GetSerializer().Serialize(setContext, change.Value.NewValue); } else { update = (update == null) ? Builders <BsonDocument> .Update.Unset(keyNamespace + change.Key.Name) : update.Unset(keyNamespace + change.Key.Name); } } setBsonWriter.WriteEndDocument(); setBsonWriter.Dispose(); foreach (var element in setDocument.Elements) { update = (update == null) ? Builders <BsonDocument> .Update.Set(keyNamespace + element.Name, element.Value) : update.Set(keyNamespace + element.Name, element.Value); } return(update); }