Repository navigation
Description
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
ajcvickers commentedon Mar 1, 2023
Duplicate of dotnet/efcore#30168.
Note for triage: consider documenting this as a breaking change.
mhkolk commentedon Mar 1, 2023
LOL. Some smart design indeed.
Updates to scaffolding docs
Updates to scaffolding docs
Updates to scaffolding docs
Tinsulate commentedon Aug 16, 2023
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.