Skip to content

Breaking change in OnConfiguring() not documented #4274

Closed

Description

@mhkolk

After rerunning the scaffold-dbcontext in EF Core 7 I stumbled upon an issue that does not seem to be documented in breaking change or anywhere else for that matter.

Include your code

This is the code that the scaffold-dbcontext creates in EF Core 6

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseNpgsql("Host=localhost:5432;Database=SetupPlatform;Username=kolektor;Password=setup");
            }
        }

As you can see there is an if present which only runs the code with the generated connnection string if optionsBuilder instance is not present.

EF Core 7 however does this and this makes our solution to no longer work (database not found), since the connection string provided at startup through configuration is not applied due to the missing if statement:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseNpgsql("Host=localhost:5432;Database=SetupPlatform;Username=kolektor;Password=setup");

This change only brings trouble and lost time to devs.

Apparently this is not the only such change in EF Core 7
https://stackoverflow.com/questions/75422460/can-i-force-entity-framework-core-7-to-not-make-icollections-read-only/75422780#75422780

Someone apparently gives little thought to this sort of things resulting in wasted development time.

Include provider and version information

EF Core version: 7.0.3
Database provider: either SqlServer or Npgsql
Target framework: .NET 7.0

Activity

  1. ajcvickers commented on Mar 1, 2023

    @ajcvickers
    Contributor

    Duplicate of dotnet/efcore#30168.

    Note for triage: consider documenting this as a breaking change.

  2. mhkolk commented on Mar 1, 2023

    @mhkolk
    Author

    This is by design.

    LOL. Some smart design indeed.

  3. transferred this issue fromdotnet/efcoreon Mar 2, 2023
  4. self-assigned this
    on Mar 2, 2023
  5. added this to the 8.0.0 milestone on Mar 2, 2023
  6. added 3 commits that reference this issue on Mar 26, 2023
    8e7869d
    f6c2422
    19b0782
  7. Tinsulate commented on Aug 16, 2023

    @Tinsulate

    Is just lost two development days hunting for this issue, as this caused some database configurations to fail very silently. Suffice to say I wasn't too happy.

  8. removed their assignment
    on Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions