예제 #1
0
        /// <summary>
        /// Sets the MySQL collation on the table associated with this entity. When you only specify the collation, MySQL implicitly sets
        /// the proper character set as well.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
        /// <param name="collation"> The name of the collation. </param>
        /// <param name="delegationModes">
        /// Finely controls where to recursively apply the character set and where not (including this entity/table).
        /// 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 so that multiple calls can be chained. </returns>
        public static IConventionEntityTypeBuilder UseCollation(
            [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
            [CanBeNull] string collation,
            DelegationModes?delegationModes = null,
            bool fromDataAnnotation         = false)
        {
            Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
            Check.NullButNotEmpty(collation, nameof(collation));
            Check.NullOrEnumValue(delegationModes, nameof(delegationModes));

            if (entityTypeBuilder.CanSetCollation(collation, fromDataAnnotation) &&
                entityTypeBuilder.CanSetCollationDelegation(delegationModes, fromDataAnnotation))
            {
                entityTypeBuilder.Metadata.SetCollation(collation, fromDataAnnotation);
                entityTypeBuilder.Metadata.SetCollationDelegation(delegationModes, fromDataAnnotation);

                return(entityTypeBuilder);
            }

            return(null);
        }