protected override void AppendWhereAffectedClause( [NotNull] StringBuilder commandStringBuilder, [NotNull] IReadOnlyList <ColumnModification> operations) { Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); Check.NotNull(operations, nameof(operations)); // If a compound key consists of an auto_increment column and a database generated column (e.g. a DEFAULT // value), then we only want to filter by `LAST_INSERT_ID()`, because we can't know what the other generated // values are. // Therefore, we filter out the key columns that are marked as `read`, but are not an auto_increment column, // so that `AppendIdentityWhereCondition()` can safely called for the remaining auto_increment column. // Because we currently use `MySqlValueGenerationStrategy.IdentityColumn` for auto_increment columns as well // as CURRENT_TIMESTAMP columns, we need to use `MySqlPropertyExtensions.IsCompatibleAutoIncrementColumn()` // to ensure, that the column is actually an auto_increment column. // See https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1300 var nonDefaultOperations = operations .Where( o => !o.IsKey || !o.IsRead || o.Property == null || !o.Property.ValueGenerated.HasFlag(ValueGenerated.OnAdd) || MySqlPropertyExtensions.IsCompatibleAutoIncrementColumn(o.Property)) .ToList() .AsReadOnly(); base.AppendWhereAffectedClause(commandStringBuilder, nonDefaultOperations); }
public override IEnumerable <IAnnotation> For(IColumn column) { if (column.PropertyMappings.Select(m => m.Property) .FirstOrDefault(p => p.GetValueGenerationStrategy() != null && p.GetValueGenerationStrategy() != MySqlValueGenerationStrategy.None) is IProperty property) { var valueGenerationStrategy = property.GetValueGenerationStrategy(); yield return(new Annotation( MySqlAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy)); } if (column.PropertyMappings.Select(m => m.Property.GetCharSet()) .FirstOrDefault(c => c != null) is string charset) { yield return(new Annotation( MySqlAnnotationNames.CharSet, charset)); } if (column.PropertyMappings.Select(m => MySqlPropertyExtensions.GetCollation(m.Property)) .FirstOrDefault(c => c != null) is string collation) { yield return(new Annotation( MySqlAnnotationNames.Collation, collation)); } if (column.PropertyMappings.Select(m => m.Property.GetSpatialReferenceSystem()) .FirstOrDefault(c => c != null) is int srid) { yield return(new Annotation( MySqlAnnotationNames.SpatialReferenceSystemId, srid)); } }