public string GetId(IUpdateEntry entry) => entry.GetCurrentValue <string>(_idProperty);
public JObject UpdateDocument(JObject document, IUpdateEntry entry) { var anyPropertyUpdated = false; foreach (var property in entry.EntityType.GetProperties()) { if (entry.EntityState == EntityState.Added || entry.IsModified(property)) { var storeName = property.GetCosmosPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); anyPropertyUpdated = true; } } } foreach (var ownedNavigation in entry.EntityType.GetNavigations()) { var fk = ownedNavigation.ForeignKey; if (!fk.IsOwnership || ownedNavigation.IsDependentToPrincipal() || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var nestedDocumentSource = _database.GetDocumentSource(fk.DeclaringEntityType); var nestedValue = entry.GetCurrentValue(ownedNavigation); var nestedPropertyName = fk.DeclaringEntityType.GetCosmosContainingPropertyName(); if (nestedValue == null) { if (document[nestedPropertyName] != null) { document[nestedPropertyName] = null; anyPropertyUpdated = true; } } else if (fk.IsUnique) { var nestedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(nestedValue, fk.DeclaringEntityType); if (nestedEntry == null) { return(document); } if (document[nestedPropertyName] is JObject nestedDocument) { nestedDocument = nestedDocumentSource.UpdateDocument(nestedDocument, nestedEntry); } else { nestedDocument = nestedDocumentSource.CreateDocument(nestedEntry); } if (nestedDocument != null) { document[nestedPropertyName] = nestedDocument; anyPropertyUpdated = true; } } else { var array = new JArray(); foreach (var dependent in (IEnumerable)nestedValue) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (dependentEntry == null) { continue; } array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry)); } document[nestedPropertyName] = array; anyPropertyUpdated = true; } } return(anyPropertyUpdated ? document : null); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int?ordinal) { var document = new JObject(); foreach (var property in entry.EntityType.GetProperties()) { var storeName = property.GetJsonPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry); } else if (entry.HasTemporaryValue(property)) { if (ordinal != null && property.IsOrdinalKeyProperty()) { entry.SetStoreGeneratedValue(property, ordinal.Value); } } } foreach (var embeddedNavigation in entry.EntityType.GetNavigations()) { var fk = embeddedNavigation.ForeignKey; if (!fk.IsOwnership || embeddedNavigation.IsOnDependent || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var embeddedValue = entry.GetCurrentValue(embeddedNavigation); var embeddedPropertyName = fk.DeclaringEntityType.GetContainingPropertyName(); if (embeddedValue == null) { document[embeddedPropertyName] = null; } else if (fk.IsUnique) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); document[embeddedPropertyName] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry); #pragma warning restore EF1001 // Internal EF Core API usage. } else { var embeddedOrdinal = 1; var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry, embeddedOrdinal)); #pragma warning restore EF1001 // Internal EF Core API usage. embeddedOrdinal++; } document[embeddedPropertyName] = array; } } return(document); }
public bool TryPropagate(IProperty property, IUpdateEntry entry) { if (_write && (entry.EntityState == EntityState.Unchanged || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)) || (entry.EntityState == EntityState.Added && Equals(_originalValue, entry.GetCurrentValue(property))))) { entry.SetStoreGeneratedValue(property, _currentValue); return(false); } return(_write); }
private static object SnapshotValue(IProperty property, ValueComparer comparer, IUpdateEntry entry) => SnapshotValue(comparer, entry.GetCurrentValue(property));
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual IProperty?FindNullPropertyInCurrentValues(IUpdateEntry entry) => Properties.FirstOrDefault(p => entry.GetCurrentValue(p) == null);
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry) { var anyPropertyUpdated = false; foreach (var property in entry.EntityType.GetProperties()) { if (entry.EntityState == EntityState.Added || entry.IsModified(property)) { var storeName = property.GetJsonPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); anyPropertyUpdated = true; } else if (entry.HasTemporaryValue(property)) { ((InternalEntityEntry)entry)[property] = entry.GetCurrentValue(property); } } } foreach (var ownedNavigation in entry.EntityType.GetNavigations()) { var fk = ownedNavigation.ForeignKey; if (!fk.IsOwnership || ownedNavigation.IsDependentToPrincipal() || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var embeddedDocumentSource = _database.GetDocumentSource(fk.DeclaringEntityType); var embeddedValue = entry.GetCurrentValue(ownedNavigation); var embeddedPropertyName = fk.DeclaringEntityType.GetContainingPropertyName(); if (embeddedValue == null) { if (document[embeddedPropertyName] != null) { document[embeddedPropertyName] = null; anyPropertyUpdated = true; } } else if (fk.IsUnique) { var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); if (embeddedEntry == null) { continue; } var embeddedDocument = embeddedDocumentSource.GetCurrentDocument(embeddedEntry); embeddedDocument = embeddedDocument != null ? embeddedDocumentSource.UpdateDocument(embeddedDocument, embeddedEntry) : embeddedDocumentSource.CreateDocument(embeddedEntry); if (embeddedDocument != null) { document[embeddedPropertyName] = embeddedDocument; anyPropertyUpdated = true; } } else { var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (embeddedEntry == null) { continue; } var embeddedDocument = embeddedDocumentSource.GetCurrentDocument(embeddedEntry); embeddedDocument = embeddedDocument != null ? embeddedDocumentSource.UpdateDocument(embeddedDocument, embeddedEntry) ?? embeddedDocument : embeddedDocumentSource.CreateDocument(embeddedEntry); array.Add(embeddedDocument); } document[embeddedPropertyName] = array; anyPropertyUpdated = true; } } return(anyPropertyUpdated ? document : null); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual int Compare(IUpdateEntry x, IUpdateEntry y) => _underlyingComparer.Compare( _converter(x.GetCurrentValue <TModel>(_property)), _converter(y.GetCurrentValue <TModel>(_property)));
public int GetHashCode(IUpdateEntry obj) => obj.GetCurrentValue <TProperty>(_property)?.GetHashCode() ?? 0;
public JObject UpdateDocument(JObject document, IUpdateEntry entry) { foreach (var property in entry.EntityType.GetProperties()) { if (property.Name != StoreKeyConvention.JObjectPropertyName && property.Name != StoreKeyConvention.IdPropertyName && (entry.EntityState == EntityState.Added || entry.IsModified(property))) { var value = entry.GetCurrentValue(property); document[property.Name] = value != null?JToken.FromObject(value) : null; } } foreach (var ownedNavigation in entry.EntityType.GetNavigations()) { var fk = ownedNavigation.ForeignKey; if (!fk.IsOwnership || ownedNavigation.IsDependentToPrincipal() || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var nestedDocumentSource = _database.GetDocumentSource(fk.DeclaringEntityType); var nestedValue = entry.GetCurrentValue(ownedNavigation); if (nestedValue == null) { document[ownedNavigation.Name] = null; } else if (fk.IsUnique) { var nestedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(nestedValue, fk.DeclaringEntityType); if (nestedEntry == null) { return(document); } var nestedDocument = (JObject)document[ownedNavigation.Name]; if (nestedDocument != null) { nestedDocumentSource.UpdateDocument(nestedDocument, nestedEntry); } else { nestedDocument = nestedDocumentSource.CreateDocument(nestedEntry); } document[ownedNavigation.Name] = nestedDocument; } else { var array = new JArray(); foreach (var dependent in (IEnumerable)nestedValue) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (dependentEntry == null) { continue; } array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry)); } document[ownedNavigation.Name] = array; } } return(document); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public static string BuildCurrentValuesString([NotNull] this IUpdateEntry entry, [NotNull] IEnumerable <IPropertyBase> properties) => "{" + string.Join(", ", properties.Select(p => p.Name + ": " + Convert.ToString(entry.GetCurrentValue(p), CultureInfo.InvariantCulture))) + "}";
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual int Compare(IUpdateEntry x, IUpdateEntry y) => _underlyingComparer.Compare( x.GetCurrentValue <TProperty>(_property), y.GetCurrentValue <TProperty>(_property));
public bool TryPropagate(IProperty property, IUpdateEntry entry) { if (_write && (entry.EntityState == EntityState.Unchanged || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)) || (entry.EntityState == EntityState.Added && Equals(_originalValue, entry.GetCurrentValue(property))))) { ((InternalEntityEntry)entry)[property] = _currentValue; return(false); } return(_write); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry, int?ordinal) { var anyPropertyUpdated = false; #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var stateManager = ((InternalEntityEntry)entry).StateManager; #pragma warning restore EF1001 // Internal EF Core API usage. foreach (var property in entry.EntityType.GetProperties()) { if (entry.EntityState == EntityState.Added || entry.IsModified(property)) { var storeName = property.GetJsonPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); anyPropertyUpdated = true; } } if (ordinal != null && entry.HasTemporaryValue(property) && property.IsOrdinalKeyProperty()) { entry.SetStoreGeneratedValue(property, ordinal.Value); } } foreach (var ownedNavigation in entry.EntityType.GetNavigations()) { var fk = ownedNavigation.ForeignKey; if (!fk.IsOwnership || ownedNavigation.IsOnDependent || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var embeddedDocumentSource = _database.GetDocumentSource(fk.DeclaringEntityType); var embeddedValue = entry.GetCurrentValue(ownedNavigation); var embeddedPropertyName = fk.DeclaringEntityType.GetContainingPropertyName(); if (embeddedValue == null) { if (document[embeddedPropertyName] != null) { document[embeddedPropertyName] = null; anyPropertyUpdated = true; } } else if (fk.IsUnique) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); #pragma warning restore EF1001 // Internal EF Core API usage. if (embeddedEntry == null) { continue; } var embeddedDocument = embeddedDocumentSource.GetCurrentDocument(embeddedEntry); embeddedDocument = embeddedDocument != null ? embeddedDocumentSource.UpdateDocument(embeddedDocument, embeddedEntry) : embeddedDocumentSource.CreateDocument(embeddedEntry); if (embeddedDocument != null) { document[embeddedPropertyName] = embeddedDocument; anyPropertyUpdated = true; } } else { var embeddedOrdinal = 0; var ordinalKeyProperty = GetOrdinalKeyProperty(fk.DeclaringEntityType); if (ordinalKeyProperty != null) { var shouldSetTemporaryKeys = false; foreach (var dependent in (IEnumerable)embeddedValue) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (embeddedEntry == null) { continue; } if ((int)embeddedEntry.GetCurrentValue(ordinalKeyProperty) != embeddedOrdinal) { shouldSetTemporaryKeys = true; break; } #pragma warning restore EF1001 // Internal EF Core API usage. embeddedOrdinal++; } if (shouldSetTemporaryKeys) { var temporaryOrdinal = -1; foreach (var dependent in (IEnumerable)embeddedValue) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (embeddedEntry == null) { continue; } embeddedEntry.SetTemporaryValue(ordinalKeyProperty, temporaryOrdinal, setModified: false); #pragma warning restore EF1001 // Internal EF Core API usage. temporaryOrdinal--; } } } embeddedOrdinal = 0; var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { #pragma warning disable EF1001 // Internal EF Core API usage. // #16707 var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); #pragma warning restore EF1001 // Internal EF Core API usage. if (embeddedEntry == null) { continue; } var embeddedDocument = embeddedDocumentSource.GetCurrentDocument(embeddedEntry); embeddedDocument = embeddedDocument != null ? embeddedDocumentSource.UpdateDocument(embeddedDocument, embeddedEntry, embeddedOrdinal) ?? embeddedDocument : embeddedDocumentSource.CreateDocument(embeddedEntry, embeddedOrdinal); array.Add(embeddedDocument); embeddedOrdinal++; } document[embeddedPropertyName] = array; anyPropertyUpdated = true; } } return(anyPropertyUpdated ? document : null); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public static string BuildCurrentValuesString([NotNull] this IUpdateEntry entry, [NotNull] IEnumerable <IPropertyBase> properties) => string.Join(", ", properties.Select(p => p.Name + ":" + entry.GetCurrentValue(p)));
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual string GetId([NotNull] IUpdateEntry entry) => entry.GetCurrentValue <string>(_idProperty);
private static FilterDefinition <TEntity> GetIdFilter <TEntity>(IUpdateEntry updateEntry) { IList <FilterDefinition <TEntity> > filterDefinitions = updateEntry.EntityType .FindPrimaryKey() .Properties .Select(property => GetPropertyFilterDefinition <TEntity>(property, updateEntry.GetCurrentValue(property))) .DefaultIfEmpty(Builders <TEntity> .Filter.Empty) .ToList(); return(filterDefinitions.Count > 1 ? Builders <TEntity> .Filter.And(filterDefinitions) : filterDefinitions[index : 0]); }