Exemple #1
0
        /// <summary>
        ///     Configures the database collation, which will be used by all columns without an explicit collation.
        /// </summary>
        /// <param name="modelBuilder"> The model builder. </param>
        /// <param name="collation"> The collation. </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 UseCollation(
            [NotNull] this IConventionModelBuilder modelBuilder,
            [CanBeNull] string collation,
            bool fromDataAnnotation = false)
        {
            if (modelBuilder.CanSetCollation(collation, fromDataAnnotation))
            {
                modelBuilder.Metadata.SetCollation(collation, fromDataAnnotation);

                return(modelBuilder);
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        ///     Configures the database collation, which will be used by all columns without an explicit collation. Also finely controls
        ///     where to recursively apply the collation and where not (including this model/database).
        /// </summary>
        /// <param name="modelBuilder"> The model builder. </param>
        /// <param name="collation"> The collation. </param>
        /// <param name="delegationModes">
        /// Finely controls where to recursively apply the collation 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 UseCollation(
            [NotNull] this IConventionModelBuilder modelBuilder,
            string collation,
            DelegationModes?delegationModes,
            bool fromDataAnnotation = false)
        {
            Check.NotNull(modelBuilder, nameof(modelBuilder));
            Check.NullButNotEmpty(collation, nameof(collation));
            Check.NullOrEnumValue(delegationModes, nameof(delegationModes));

            if (modelBuilder.CanSetCollation(collation, fromDataAnnotation) &&
                modelBuilder.CanSetCollationDelegation(delegationModes, fromDataAnnotation))
            {
                modelBuilder.Metadata.SetCollation(collation, fromDataAnnotation);
                modelBuilder.Metadata.SetCharSetDelegation(delegationModes, fromDataAnnotation);

                return(modelBuilder);
            }

            return(null);
        }