Skip to content

HiLo sequences are being dropped when specifying a default schema #28223

Closed

Description

@ChristopherVR

I'm having an issue where with each new migration file being generated our HiLo sequences are being dropped. This only happens if I add a default schema to the DbContext. This is the result when creating new migrations:

image

image

Here is the necessary code to reproduce this issue:

protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
        modelBuilder.HasDefaultSchema("MyDefaultSchema");
        
         modelBuilder.HasSequence<int>("HiLoTestSeq", "MyDefaultSchema")
            .StartsAt(10) // Make provision for defaults
            .IncrementsBy(5);
}
   
public class TestSchemaEntity
{
    public int Id { get; private set; }
}

internal class TestSchemaEntityTypeConfiguration : IEntityTypeConfiguration<TestSchemaEntity>
{
    public void Configure(EntityTypeBuilder<TestSchemaEntity> builder)
    {
        builder.ToTable("TestSchemaTable", "MyDefaultSchema");

        builder.HasKey(r => r.Id);

        builder.Property(r => r.Id).UseHiLo("HiLoTestSeq", "MyDefaultSchema");
    }
}

EF Core version:
Database provider:  Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Window 11
IDE:  Visual Studio 2022 16.3

Activity

  1. added this to the 7.0.0 milestone on Jun 15, 2022
  2. bricelam commented on Aug 31, 2022

    @bricelam
    Contributor

    Looks like this stems from some very strange behavior in FindSequence.

    modelBuilder
        .HasDefaultSchema("dbo")
        .HasSequence("TheSequence");
    
    // Not found
    model.FindSequence("TheSequence", "dbo");
    
    // Found. Result's schema is dbo
    model.FindSequence("TheSequence");
    modelBuilder
        .HasDefaultSchema("dbo")
        .HasSequence("TheSequence", "dbo");
    
    // Found
    model.FindSequence("TheSequence", "dbo");
    
    // Not found
    model.FindSequence("TheSequence");
  3. added 2 commits that reference this issue on Aug 31, 2022
    004620a
    3c6b0d3
  4. modified the milestones: 7.0.0, on Sep 2, 2022
  5. modified the milestones: , 7.0.0 on Nov 5, 2022
  6. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions