添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account [NotMapped] public IDictionary<string, string> RuntimeStringProperties { get; set; } public DateTime CreatedAt { get; set; } public DateTime? UpdatedAt { get; set; } public DateTime? DeletedAt { get; set; } public int SortingOrder { get; set; } [Timestamp] public byte[] RowVersion { get; set; }
    public class SubscriptionCharacterLocationConfiguration : IEntityTypeConfiguration<SubscriptionCharacterLocation>
        public void Configure(EntityTypeBuilder<SubscriptionCharacterLocation> builder)
            builder.HasKey(c => new { c.CharacterId, c.LocationId });
            builder.HasOne(c => c.Character)
               .WithMany(c => c.LocationSubscriptions)
               .HasForeignKey(pc => pc.CharacterId);
            builder.HasOne(c => c.Location)
               .WithMany(p => p.CharacterSubscriptions)
               .HasForeignKey(pc => pc.LocationId);
    [Table("Subscriptions_CharacterLocation")]
    public class SubscriptionCharacterLocation : EntityBase
        public int CharacterId { get; set; }
        public Character Character { get; set; }
        public Guid LocationId { get; set; }
        public Location Location { get; set; }

The issue

RowVersion is always being generated, no issues however with running the solution.

            migrationBuilder.AlterColumn<DateTime>(
                name: "RowVersion",
                table: "Subscriptions_CharacterLocation",
                rowVersion: true,
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp(6)",
                oldNullable: true)
                .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn);

Further technical details

MySQL version: new Version(10, 1, 31), ServerType.MariaDb
Operating system: Windows 10
Pomelo.EntityFrameworkCore.MySql version: 3.1.1
Microsoft.AspNetCore.App version: 3.1

Other details about my project setup:

Looks correct to me. You used the [Timestamp] attribute (which results in a rowversion) and you got a rowversion.
Depending on your scenario, you could also use the timestamp or timestamp(6) column type in combination with .ValueGeneratedOnAddOrUpdate() to generate something like this:

CREATE TABLE `SubscriptionCharacterLocation` (
  `RowVersion` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

What is it you would expect in your scenario and why do you think the current behavior is/could be a problem?

I have exactly the same problem.
Every time I add migration I get following code even if the model was not changed.

            migrationBuilder.AlterColumn<DateTime>(
                name: "Ts",
                table: "WaterMachines",
                rowVersion: true,
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp(6)",
                oldNullable: true)
                .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn);
            migrationBuilder.AlterColumn<DateTime>(
                name: "Ts",
                table: "WaterItems",
                rowVersion: true,
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp(6)",
                oldNullable: true)
                .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn);
            migrationBuilder.AlterColumn<DateTime>(
                name: "Ts",
                table: "Orders",
                rowVersion: true,
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp(6)",
                oldNullable: true)
                .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn);
          

Making the RowVersion property non-nullable, will workaround this issue:

// Using Data Annotations: public class MyEntity [Required] // <-- Non-Nullable [Timestamp] public byte[] RowVersion { get; set; } // Using FluentAPI: public class MyEntity public byte[] RowVersion { get; set; } public class MyContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity<MyEntity>(entity => entity.Property("RowVersion") .IsRequired() // <-- Non-Nullable .IsConcurrencyToken() .ValueGeneratedOnAddOrUpdate(); });

After updating EF Core and Pomelo MySQL to version 7, I would get an error on SaveChanges stating invalid SQL on RETURNING RowVersion, so I tried the mentioned workaround. I'm using MariaDB 10.3.

In my model I have the following, which worked fine with everything on version 6:

[Timestamp]
public byte[]? RowVersion { get; set; }

After changing it to the above workaround like so:

[Required]
[Timestamp]
public byte[] RowVersion { get; set; }

I'm getting the following error trying to apply the migration:

Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE `R` MODIFY COLUMN `RowVersion` timestamp(6) NOT NULL DEFAULT '0001-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6);