Example #1
0
        /// <summary>
        /// Sets the default character set to use for the model/database.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="charSet">The name of the character set to use.</param>
        /// <param name="delegationModes">
        /// Finely controls where to recursively apply the character set and where not (including this model/database).
        /// Implicitly uses <see cref="DelegationModes.ApplyToAll"/> if set to <see langword="null"/>.
        /// </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 IConventionModelBuilder HasCharSet(
            [NotNull] this IConventionModelBuilder modelBuilder,
            [CanBeNull] string charSet,
            DelegationModes?delegationModes = null,
            bool fromDataAnnotation         = false)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));
            Check.NullButNotEmpty(charSet, nameof(charSet));
            Check.NullOrEnumValue(delegationModes, nameof(delegationModes));

            if (modelBuilder.CanSetCharSet(charSet, fromDataAnnotation) &&
                modelBuilder.CanSetCharSetDelegation(delegationModes, fromDataAnnotation))
            {
                modelBuilder.Metadata.SetCharSet(charSet, fromDataAnnotation);
                modelBuilder.Metadata.SetCharSetDelegation(delegationModes, fromDataAnnotation);

                return(modelBuilder);
            }

            return(null);
        }
Example #2
0
 /// <summary>
 ///     Returns a value indicating whether the given character set can be set as default.
 /// </summary>
 /// <param name="modelBuilder"> The model builder. </param>
 /// <param name="charSet"> The character set. </param>
 /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
 /// <returns> <see langword="true" /> if the given character set can be set as default. </returns>
 public static bool CanSetCharSet(
     [NotNull] this IConventionModelBuilder modelBuilder,
     [CanBeNull] CharSet charSet,
     bool fromDataAnnotation = false)
 => modelBuilder.CanSetCharSet(charSet?.Name, fromDataAnnotation);