protected virtual string GetActualPropertyCharSet(IProperty[] properties, DelegationModes currentLevel) { return(properties.Select(p => p.GetCharSet()).FirstOrDefault(s => s is not null) ?? properties.Select( p => p.FindTypeMapping() is MySqlStringTypeMapping { IsNationalChar: false }
private static void HandleCollationDelegation <TOperation>( TOperation operation, DelegationModes delegationModes, Action <TOperation> resetCollationProperty = null) where TOperation : MigrationOperation { // If the database collation should not be applied to the database itself, we need to reset the Collation property. // It the CollationDelegation annotation does not exist, it is ApplyToAll implicitly. if (operation[MySqlAnnotationNames.CollationDelegation] is DelegationModes databaseCollationDelegation) { // Don't leak the CollationDelegation annotation to the MigrationOperation. operation[MySqlAnnotationNames.CollationDelegation] = null; if (!databaseCollationDelegation.HasFlag(delegationModes)) { if (resetCollationProperty == null) { operation[RelationalAnnotationNames.Collation] = null; } else { resetCollationProperty(operation); } } } }
protected virtual string GetActualEntityTypeCharSet(IEntityType entityType, DelegationModes currentLevel) { // There are the following variations at the entity level: // 1. entityTypeBuilder.HasCharSet(null, null) [or no call at all] // -> Check the charset and delegation at the database level. // 2. a. entityTypeBuilder.HasCharSet(null, DelegationMode.ApplyToAll) // b. entityTypeBuilder.HasCharSet(null, DelegationMode.ApplyToColumns) // -> Do not explicitly use any charset. // 3. a. entityTypeBuilder.HasCharSet("latin1") // b. entityTypeBuilder.HasCharSet("latin1", DelegationMode.ApplyToAll) // c. entityTypeBuilder.HasCharSet("latin1", DelegationMode.ApplyToColumns) // -> Explicitly use the specified charset. return((entityType.GetCharSet() is not null || // 3abc entityType.GetCharSet() is null && entityType.GetCharSetDelegation() is not null) && // 2ab entityType.GetActualCharSetDelegation().HasFlag(currentLevel) // 3abc, 2ab ? entityType.GetCharSet() // An explicitly defined collation on the current entity level takes precedence over an inherited charset. : GetActualModelCharSet(entityType.Model, currentLevel) is string charSet && // 1 (currentLevel != DelegationModes.ApplyToTables || entityType.GetCollation() is not string collation || !entityType.GetActualCollationDelegation().HasFlag(DelegationModes.ApplyToTables) || collation.StartsWith(charSet, StringComparison.OrdinalIgnoreCase)) ? charSet : null); }
protected virtual string GetActualModelCharSet(IModel model, DelegationModes currentLevel) { // If neither character set nor collation has been explicitly defined for the model, and no delegation has been setup, we use // Pomelo's universal fallback default character set (which is `utf8mb4`) and apply it to all database objects. return(model.GetCharSet() is null && model.GetCharSetDelegation() is null && model.GetCollation() is null && model.GetCollationDelegation() is null ? _options.DefaultCharSet.Name : model.GetActualCharSetDelegation().HasFlag(currentLevel) ? model.GetCharSet() : null); }
private static void HandleCharSetDelegation(MigrationOperation operation, DelegationModes delegationModes) { // If the character set should not be applied to the database itself, we need to remove the CharSet annotation. // It the CharSetDelegation annotation does not exist, it is ApplyToAll implicitly. if (operation[MySqlAnnotationNames.CharSetDelegation] is DelegationModes charSetDelegation) { // Don't leak the CharSetDelegation annotation to the MigrationOperation. operation[MySqlAnnotationNames.CharSetDelegation] = null; if (!charSetDelegation.HasFlag(delegationModes)) { operation[MySqlAnnotationNames.CharSet] = null; } } }
protected virtual string GetActualModelCollation(IModel model, DelegationModes currentLevel) { return(model.GetActualCollationDelegation().HasFlag(currentLevel) ? model.GetCollation() : null); }
/// <summary> /// Initializes a new instance of the <see cref="MySqlCharSetAttribute" /> class. /// </summary> /// <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. /// Ignored when <see cref="MySqlCharSetAttribute"/> is applied to properties/columns. /// </param> public MySqlCharSetAttribute(string charSet, DelegationModes delegationModes) : this(charSet, (DelegationModes?)delegationModes) { }
/// <summary> /// Initializes a new instance of the <see cref="MySqlCollationAttribute" /> class. /// </summary> /// <param name="collation"> The name of the collation to use. </param> /// <param name="delegationModes"> /// Finely controls where to recursively apply the collation and where not. /// Ignored when <see cref="MySqlCollationAttribute"/> is applied to properties/columns. /// </param> public MySqlCollationAttribute(string collation, DelegationModes delegationModes) : this(collation, (DelegationModes?)delegationModes) { }