Example #1
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);
        }
Example #2
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);
        }