/// <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.GetCurrentValue(property)); } 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) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); document[embeddedPropertyName] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry); } else { var embeddedOrdinal = 0; var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry, embeddedOrdinal)); embeddedOrdinal++; } document[embeddedPropertyName] = array; } } return(document); }
/// <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(IUpdateEntry entry) { var document = new JObject(); foreach (var property in entry.EntityType.GetProperties()) { var storeName = property.GetCosmosPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); } else if (entry.HasTemporaryValue(property)) { ((InternalEntityEntry)entry)[property] = entry.GetCurrentValue(property); } } foreach (var embeddedNavigation in entry.EntityType.GetNavigations()) { var fk = embeddedNavigation.ForeignKey; if (!fk.IsOwnership || embeddedNavigation.IsDependentToPrincipal() || fk.DeclaringEntityType.IsDocumentRoot()) { continue; } var embeddedValue = entry.GetCurrentValue(embeddedNavigation); var embeddedPropertyName = fk.DeclaringEntityType.GetCosmosContainingPropertyName(); if (embeddedValue == null) { document[embeddedPropertyName] = null; } else if (fk.IsUnique) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); document[embeddedPropertyName] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry); } else { var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry)); } document[embeddedPropertyName] = array; } } return(document); }
public JObject CreateDocument(IUpdateEntry entry) { var document = new JObject(); foreach (var property in entry.EntityType.GetProperties()) { var storeName = property.Cosmos().PropertyName; if (storeName != "") { var value = entry.GetCurrentValue(property); document[storeName] = 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 nestedValue = entry.GetCurrentValue(ownedNavigation); if (nestedValue == null) { document[ownedNavigation.Name] = null; } else if (fk.IsUnique) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(nestedValue, fk.DeclaringEntityType); document[ownedNavigation.Name] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry); } else { var array = new JArray(); foreach (var dependent in (IEnumerable)nestedValue) { var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry)); } document[ownedNavigation.Name] = array; } } return(document); }