Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

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

Closed
ChristopherVR opened this issue Jun 14, 2022 · 1 comment · Fixed by #28943
Closed

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

ChristopherVR opened this issue Jun 14, 2022 · 1 comment · Fixed by #28943
Assignees
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@ChristopherVR
Copy link

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
@bricelam
Copy link
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");

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 31, 2022
bricelam added a commit to bricelam/efcore that referenced this issue Aug 31, 2022
@bricelam bricelam modified the milestones: 7.0.0, 7.0.0-rc2 Sep 2, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-rc2, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants