/// <summary>
 ///     Called after a key is added to the entity type.
 /// </summary>
 /// <param name="keyBuilder"> The builder for the key. </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext <IConventionKeyBuilder> context)
 {
     if (keyBuilder.Metadata.DeclaringEntityType.GetSqlServerIsMemoryOptimized())
     {
         keyBuilder.ForSqlServerIsClustered(false);
     }
 }
        public override IConventionKeyBuilder?OnKeyAdded(IConventionKeyBuilder keyBuilder)
        {
            if (!keyBuilder.Metadata.DeclaringEntityType.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _keyBuilderConventionContext.ResetState(keyBuilder);
                foreach (var keyConvention in _conventionSet.KeyAddedConventions)
                {
                    if (!keyBuilder.Metadata.IsInModel)
                    {
                        return(null);
                    }

                    keyConvention.ProcessKeyAdded(keyBuilder, _keyBuilderConventionContext);
                    if (_keyBuilderConventionContext.ShouldStopProcessing())
                    {
                        return(_keyBuilderConventionContext.Result);
                    }
                }
            }

            return(!keyBuilder.Metadata.IsInModel ? null : keyBuilder);
        }
        public override IConventionAnnotation?OnKeyAnnotationChanged(
            IConventionKeyBuilder keyBuilder,
            string name,
            IConventionAnnotation?annotation,
            IConventionAnnotation?oldAnnotation)
        {
            if (!keyBuilder.Metadata.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _annotationConventionContext.ResetState(annotation);
                foreach (var keyConvention in _conventionSet.KeyAnnotationChangedConventions)
                {
                    keyConvention.ProcessKeyAnnotationChanged(
                        keyBuilder, name, annotation, oldAnnotation, _annotationConventionContext);
                    if (_annotationConventionContext.ShouldStopProcessing())
                    {
                        return(_annotationConventionContext.Result);
                    }
                }
            }

            return(annotation);
        }
 public static IConventionKeyBuilder IsDocumentOwnershipKey(
     this IConventionKeyBuilder keyBuilder,
     bool isDocumentOwnershipKey)
 {
     Check.NotNull(keyBuilder, nameof(keyBuilder))
     .Document().IsOwnershipKey = isDocumentOwnershipKey;
     return(keyBuilder);
 }
Example #5
0
        /// <summary>
        ///     Returns a value indicating whether the key can be configured as clustered.
        /// </summary>
        /// <param name="keyBuilder"> The builder for the key being configured. </param>
        /// <param name="clustered"> A value indicating whether the key is clustered. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns> <c>true</c> if the key can be configured as clustered. </returns>
        public static bool CanSetIsClustered(
            [NotNull] this IConventionKeyBuilder keyBuilder,
            bool?clustered,
            bool fromDataAnnotation = false)
        {
            Check.NotNull(keyBuilder, nameof(keyBuilder));

            return(keyBuilder.CanSetAnnotation(SqlServerAnnotationNames.Clustered, clustered, fromDataAnnotation));
        }
 public override IConventionAnnotation?OnKeyAnnotationChanged(
     IConventionKeyBuilder keyBuilder,
     string name,
     IConventionAnnotation?annotation,
     IConventionAnnotation?oldAnnotation)
 {
     Add(new OnKeyAnnotationChangedNode(keyBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
 /// <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 IConventionAnnotation OnKeyAnnotationChanged(
     [NotNull] IConventionKeyBuilder keyBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnKeyAnnotationChanged(
     keyBuilder,
     name,
     annotation,
     oldAnnotation);
        /// <summary>
        ///     Called after a key is added to the entity type.
        /// </summary>
        /// <param name="keyBuilder"> The builder for the key. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext <IConventionKeyBuilder> context)
        {
            var key = keyBuilder.Metadata;

            foreach (var index in key.DeclaringEntityType.GetDerivedTypesInclusive()
                     .SelectMany(t => t.GetDeclaredIndexes())
                     .Where(i => AreIndexedBy(i.Properties, i.IsUnique, key.Properties, true)).ToList())
            {
                RemoveIndex(index);
            }
        }
Example #9
0
        /// <summary>
        ///     Configures the name of the key constraint in the database when targeting a relational database.
        /// </summary>
        /// <param name="keyBuilder"> The builder for the key being configured. </param>
        /// <param name="name"> The name of the key. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionKeyBuilder HasName(
            [NotNull] this IConventionKeyBuilder keyBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
        {
            if (keyBuilder.CanSetName(name, fromDataAnnotation))
            {
                keyBuilder.Metadata.SetName(name, fromDataAnnotation);
                return(keyBuilder);
            }

            return(null);
        }
 public OnKeyAnnotationChangedNode(
     IConventionKeyBuilder keyBuilder,
     string name,
     IConventionAnnotation?annotation,
     IConventionAnnotation?oldAnnotation)
 {
     KeyBuilder    = keyBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Example #11
0
        /// <inheritdoc />
        public virtual void ProcessKeyAdded(
            IConventionKeyBuilder keyBuilder,
            IConventionContext <IConventionKeyBuilder> context)
        {
            var entityTypeBuilder = keyBuilder.Metadata.DeclaringEntityType.Builder;

            if (entityTypeBuilder.Metadata.GetKeys().Count() == 1)
            {
                ProcessIdProperty(entityTypeBuilder);
                ProcessJObjectProperty(entityTypeBuilder);
            }
        }
Example #12
0
        /// <summary>
        ///     Configures the name of the key constraint in the database when targeting a relational database.
        /// </summary>
        /// <remarks>
        ///     See <see href="https://aka.ms/efcore-docs-keys">Keys</see> for more information.
        /// </remarks>
        /// <param name="keyBuilder">The builder for the key being configured.</param>
        /// <param name="name">The name of the key.</param>
        /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionKeyBuilder?HasName(
            this IConventionKeyBuilder keyBuilder,
            string?name,
            bool fromDataAnnotation = false)
        {
            if (keyBuilder.CanSetName(name, fromDataAnnotation))
            {
                keyBuilder.Metadata.SetName(name, fromDataAnnotation);
                return(keyBuilder);
            }

            return(null);
        }
Example #13
0
        /// <summary>
        ///     Configures whether the key is clustered when targeting SQL Server.
        /// </summary>
        /// <param name="keyBuilder"> The builder for the key being configured. </param>
        /// <param name="clustered"> A value indicating whether the key is clustered. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionKeyBuilder IsClustered(
            [NotNull] this IConventionKeyBuilder keyBuilder,
            bool?clustered,
            bool fromDataAnnotation = false)
        {
            if (keyBuilder.CanSetIsClustered(clustered, fromDataAnnotation))
            {
                keyBuilder.Metadata.SetIsClustered(clustered, fromDataAnnotation);
                return(keyBuilder);
            }

            return(null);
        }
Example #14
0
        public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext <IConventionKeyBuilder> context)
        {
            var key = keyBuilder.Metadata;

            foreach (var foreignKey in key.DeclaringEntityType.GetDerivedTypesInclusive()
                     .SelectMany(t => t.GetDeclaredForeignKeys()).ToList())
            {
                if (key.Properties.All(p => foreignKey.Properties.Contains(p)) &&
                    (!foreignKey.IsUnique || foreignKey.DeclaringEntityType.BaseType != null))
                {
                    foreignKey.Builder.HasForeignKey((IReadOnlyList <Property>?)null);
                }
            }
        }
Example #15
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 virtual IConventionAnnotation OnKeyAnnotationChanged(
            [NotNull] IConventionKeyBuilder keyBuilder,
            [NotNull] string name,
            [CanBeNull] IConventionAnnotation annotation,
            [CanBeNull] IConventionAnnotation oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnKeyAnnotationChanged(
                       keyBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }
Example #16
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 virtual IConventionAnnotation?OnKeyAnnotationChanged(
            IConventionKeyBuilder keyBuilder,
            string name,
            IConventionAnnotation?annotation,
            IConventionAnnotation?oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnKeyAnnotationChanged(
                       keyBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }
Example #17
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 virtual IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder)
 => _scope.OnKeyAdded(keyBuilder);
Example #18
0
 public abstract IConventionAnnotation OnKeyAnnotationChanged(
     [NotNull] IConventionKeyBuilder keyBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation);
Example #19
0
 public abstract IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder);
Example #20
0
 public static IConventionKeyBuilder ForSqlServerIsClustered(
     [NotNull] this IConventionKeyBuilder keyBuilder,
     bool?clustered,
     bool fromDataAnnotation = false)
 => keyBuilder.IsClustered(clustered, fromDataAnnotation);
 public abstract IConventionKeyBuilder?OnKeyAdded(IConventionKeyBuilder keyBuilder);
 public OnKeyAddedNode(IConventionKeyBuilder keyBuilder)
 {
     KeyBuilder = keyBuilder;
 }
 public abstract IConventionAnnotation?OnKeyAnnotationChanged(
     IConventionKeyBuilder keyBuilder,
     string name,
     IConventionAnnotation?annotation,
     IConventionAnnotation?oldAnnotation);
 public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilder)
 {
     Add(new OnKeyAddedNode(keyBuilder));
     return(keyBuilder);
 }
Example #25
0
 /// <summary>
 ///     Returns a value indicating whether the given name can be set for the key constraint.
 /// </summary>
 /// <remarks>
 ///     See <see href="https://aka.ms/efcore-docs-keys">Keys</see> for more information.
 /// </remarks>
 /// <param name="keyBuilder">The builder for the key being configured.</param>
 /// <param name="name">The name of the index.</param>
 /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
 /// <returns><see langword="true" /> if the given name can be set for the key constraint.</returns>
 public static bool CanSetName(
     this IConventionKeyBuilder keyBuilder,
     string?name,
     bool fromDataAnnotation = false)
 => keyBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation);
Example #26
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 virtual IConventionKeyBuilder?OnKeyAdded(IConventionKeyBuilder keyBuilder)
 => _scope.OnKeyAdded(keyBuilder);
Example #27
0
 public void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext <IConventionKeyBuilder> context)
 => keyBuilder.HasName(RewriteName(keyBuilder.Metadata.GetName()));
Example #28
0
 /// <inheritdoc />
 public void ProcessKeyAdded(
     IConventionKeyBuilder keyBuilder,
     IConventionContext <IConventionKeyBuilder> _)
 => Process(keyBuilder.Metadata.DeclaringEntityType.Builder);
 /// <summary>
 ///     Returns a value indicating whether the key can be configured as clustered.
 /// </summary>
 /// <remarks>
 ///     See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
 ///     <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
 ///     for more information and examples.
 /// </remarks>
 /// <param name="keyBuilder">The builder for the key being configured.</param>
 /// <param name="clustered">A value indicating whether the key is clustered.</param>
 /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
 /// <returns><see langword="true" /> if the key can be configured as clustered.</returns>
 public static bool CanSetIsClustered(
     this IConventionKeyBuilder keyBuilder,
     bool?clustered,
     bool fromDataAnnotation = false)
 => keyBuilder.CanSetAnnotation(SqlServerAnnotationNames.Clustered, clustered, fromDataAnnotation);
Example #30
0
 /// <summary>
 ///     Returns a value indicating whether the given name can be set for the key constraint.
 /// </summary>
 /// <param name="keyBuilder"> The builder for the key being configured. </param>
 /// <param name="name"> The name of the index. </param>
 /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
 /// <returns> <see langword="true" /> if the given name can be set for the key constraint. </returns>
 public static bool CanSetName(
     [NotNull] this IConventionKeyBuilder keyBuilder,
     [CanBeNull] string name,
     bool fromDataAnnotation = false)
 => keyBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation);