public static bool IsOrdinalKeyProperty([NotNull] this IReadOnlyProperty property) { Check.DebugAssert( property.DeclaringEntityType.IsOwned(), $"Expected {property.DeclaringEntityType.DisplayName()} to be owned."); Check.DebugAssert(property.GetJsonPropertyName().Length == 0, $"Expected {property.Name} to be non-persisted."); return(property.FindContainingPrimaryKey() is IReadOnlyKey key && key.Properties.Count > 1 && !property.IsForeignKey() && property.ClrType == typeof(int) && property.ValueGenerated == ValueGenerated.OnAdd); }
private static string GetDefaultJsonPropertyName(IReadOnlyProperty property) { var entityType = property.DeclaringEntityType; var ownership = entityType.FindOwnership(); if (ownership != null && !entityType.IsDocumentRoot()) { var pk = property.FindContainingPrimaryKey(); if (pk != null && (property.ClrType == typeof(int) || ownership.Properties.Contains(property)) && pk.Properties.Count == ownership.Properties.Count + (ownership.IsUnique ? 0 : 1) && ownership.Properties.All(fkProperty => pk.Properties.Contains(fkProperty))) { return(""); } } return(property.Name); }
/// <summary> /// Returns the store value generation strategy to set for the given property. /// </summary> /// <param name="property"> The property. </param> /// <returns> The store value generation strategy to set for the given property. </returns> public static ValueGenerated?GetValueGenerated(IReadOnlyProperty property) => !property.GetContainingForeignKeys().Any(fk => !fk.IsBaseLinking()) && ShouldHaveGeneratedProperty(property.FindContainingPrimaryKey()) && CanBeGenerated(property) ? ValueGenerated.OnAdd : (ValueGenerated?)null;