예제 #1
0
 public static PropertySaveBehavior GetAfterSaveBehavior([NotNull] this IReadOnlyProperty property)
 => (PropertySaveBehavior?)Check.NotNull(property, nameof(property))[CoreAnnotationNames.AfterSaveBehavior]
 ?? (property.IsKey()
             ? PropertySaveBehavior.Throw
             : property.ValueGenerated.ForUpdate()
                 ? PropertySaveBehavior.Ignore
                 : PropertySaveBehavior.Save);
예제 #2
0
 /// <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 static bool RequiresValueGenerator(this IReadOnlyProperty property)
 => (property.ValueGenerated.ForAdd() &&
     property.IsKey() &&
     (!property.IsForeignKey() ||
      property.IsForeignKeyToSelf() ||
      (property.GetContainingForeignKeys().All(fk => fk.Properties.Any(p => p != property && p.IsNullable))))) ||
 property.GetValueGeneratorFactory() != null;
예제 #3
0
        public static bool IsForeignKeyToSelf([NotNull] this IReadOnlyProperty property)
        {
            Check.DebugAssert(property.IsKey(), "Only call this method for properties known to be part of a key.");

            foreach (var foreignKey in property.GetContainingForeignKeys())
            {
                var propertyIndex = foreignKey.Properties.IndexOf(property);
                if (propertyIndex == foreignKey.PrincipalKey.Properties.IndexOf(property))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        public static string ToDebugString(
            [NotNull] this IReadOnlyProperty property,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder.Append(indentString);

            var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;

            if (singleLine)
            {
                builder.Append($"Property: {property.DeclaringEntityType.DisplayName()}.");
            }

            builder.Append(property.Name).Append(" (");

            var field = property.GetFieldName();

            if (field == null)
            {
                builder.Append("no field, ");
            }
            else if (!field.EndsWith(">k__BackingField", StringComparison.Ordinal))
            {
                builder.Append(field).Append(", ");
            }

            builder.Append(property.ClrType.ShortDisplayName()).Append(")");

            if (property.IsShadowProperty())
            {
                builder.Append(" Shadow");
            }

            if (property.IsIndexerProperty())
            {
                builder.Append(" Indexer");
            }

            if (!property.IsNullable)
            {
                builder.Append(" Required");
            }

            if (property.IsPrimaryKey())
            {
                builder.Append(" PK");
            }

            if (property.IsForeignKey())
            {
                builder.Append(" FK");
            }

            if (property.IsKey() &&
                !property.IsPrimaryKey())
            {
                builder.Append(" AlternateKey");
            }

            if (property.IsIndex())
            {
                builder.Append(" Index");
            }

            if (property.IsConcurrencyToken)
            {
                builder.Append(" Concurrency");
            }

            if (property.GetBeforeSaveBehavior() != PropertySaveBehavior.Save)
            {
                builder.Append(" BeforeSave:").Append(property.GetBeforeSaveBehavior());
            }

            if (property.GetAfterSaveBehavior() != PropertySaveBehavior.Save)
            {
                builder.Append(" AfterSave:").Append(property.GetAfterSaveBehavior());
            }

            if (property.ValueGenerated != ValueGenerated.Never)
            {
                builder.Append(" ValueGenerated.").Append(property.ValueGenerated);
            }

            if (property.GetMaxLength() != null)
            {
                builder.Append(" MaxLength(").Append(property.GetMaxLength()).Append(")");
            }

            if (property.IsUnicode() == false)
            {
                builder.Append(" Ansi");
            }

            if (property.GetPropertyAccessMode() != PropertyAccessMode.PreferField)
            {
                builder.Append(" PropertyAccessMode.").Append(property.GetPropertyAccessMode());
            }

            if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 &&
                ((Annotatable)property).IsReadOnly)
            {
                var indexes = ((IProperty)property).GetPropertyIndexes();
                builder.Append(" ").Append(indexes.Index);
                builder.Append(" ").Append(indexes.OriginalValueIndex);
                builder.Append(" ").Append(indexes.RelationshipIndex);
                builder.Append(" ").Append(indexes.ShadowIndex);
                builder.Append(" ").Append(indexes.StoreGenerationIndex);
            }

            if (!singleLine && (options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(property.AnnotationsToDebugString(indent + 2));
            }

            return(builder.ToString());
        }
예제 #5
0
 public static bool RequiresValueGenerator([NotNull] this IReadOnlyProperty property)
 => (property.ValueGenerated.ForAdd() &&
     property.IsKey() &&
     (!property.IsForeignKey() || property.IsForeignKeyToSelf())) ||
 property.GetValueGeneratorFactory() != null;
예제 #6
0
 public static bool RequiresOriginalValue([NotNull] this IReadOnlyProperty property)
 => property.DeclaringEntityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.ChangingAndChangedNotifications ||
 property.IsConcurrencyToken ||
 property.IsKey() ||
 property.IsForeignKey() ||
 property.IsUniqueIndex();