Entity Framework 核心 6 - IEntityTypeConfiguration 单独配置 Class

Entity Framework Core 6 - IEntityTypeConfiguration Separate Configuration Class

使用 EF Core 6,可以在模型构建器中设置序列,然后使用以下方式为属性生成值。

//DBContex Class
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.HasSequence<int>("OrderNumbers");

    modelBuilder.Entity<Order>()
        .Property(o => o.OrderNo)
        .HasDefaultValueSql("NEXT VALUE FOR shared.OrderNumbers");
}

我正在尝试将 DbConfigurations 移动到特定于模型的单独配置 class:

//Seperate Configuration Class
public class OrdertEntityConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.HasSequence("OrderNumbers").StartsAt(1000);

    }
}

但它给出了以下错误:

Error CS1929 'EntityTypeBuilder' does not contain a definition for 'HasSequence' and the best extension method overload 'RelationalModelBuilderExtensions.HasSequence(ModelBuilder, string, string?)' requires a receiver of type 'ModelBuilder'

任何解决方案?

序列不属于实体,必须保留在main DbContext