使用EF和MySql在生成的迁移上手动设置注释

使用EF和MySql在生成的迁移上手动设置注释,mysql,entity-framework,Mysql,Entity Framework,我的类中有一个属性,它不是我想要自动递增的主键。主键是GUID,因此我仍然可以在表中的另一列上使用自动递增函数。此外,我不能将主键更改为int,因为GUID键是在基类中定义的。我可以在生成的迁移中手动向属性添加.Annotation(“MySQL:AutoIncrement”,true),但我担心编辑迁移会导致将来的问题。我通过.AddAnnotation(,)方法找到了答案,但它没有产生预期的结果 另外,[DatabaseGenerated(DatabaseGeneratedOption.Id

我的类中有一个属性,它不是我想要自动递增的主键。主键是GUID,因此我仍然可以在表中的另一列上使用自动递增函数。此外,我不能将主键更改为int,因为GUID键是在基类中定义的。我可以在生成的迁移中手动向属性添加
.Annotation(“MySQL:AutoIncrement”,true)
,但我担心编辑迁移会导致将来的问题。我通过
.AddAnnotation(,)
方法找到了答案,但它没有产生预期的结果

另外,
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
不会产生所需的结果

我希望:

builder.Entity<Editor>().Property(p => p.CreatorId).ValueGeneratedOnAdd().Metadata.AfterSaveBehavior = PropertySaveBehavior.Throw;
builder.Entity<Editor>().Property(p => p.CreatorId).Metadata.AddAnnotation("MySQL:AutoIncrement", true);
builder.Entity();
builder.Entity().Property(p=>p.CreatorId).Metadata.AddAnnotation(“MySQL:AutoIncrement”,true);
这将使:

migrationBuilder.CreateTable(
    name: "editor",
    columns: table => new
    {
       CreatorId = table.Column<int>(nullable: false).Annotation("MySQL:AutoIncrement", true)
       ...
migrationBuilder.CreateTable(
姓名:“编辑”,
列:表=>new
{
CreatorId=table.Column(null:false).Annotation(“MySQL:AutoIncrement”,true)
...
MySql.Data.EntityFrameworkCore:8.0.18.0


Microsoft.EntityFrameworkCore:2.2.4

在使用DotPeek查看MySql.Data.EntityFramework的代码后,似乎无法使用fluentApi或属性达到所需效果,因为它只会添加注释(如果注释是主键)。无论在数据库中是否可行