diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs index ccbe3121bc7..55a8a8cdd3b 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs @@ -125,6 +125,13 @@ protected virtual void GenerateClass( GenerateOnModelCreating(model, useDataAnnotations); } + _sb.AppendLine(); + + using (_sb.Indent()) + { + _sb.AppendLine("partial void OnModelCreatingPartial(ModelBuilder modelBuilder);"); + } + _sb.AppendLine("}"); } @@ -319,6 +326,13 @@ protected virtual void GenerateOnModelCreating( } } + _sb.AppendLine(); + + using (_sb.Indent()) + { + _sb.AppendLine("OnModelCreatingPartial(modelBuilder);"); + } + _sb.AppendLine("}"); } diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs index 4e0108dc4fd..4a415771671 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs @@ -48,7 +48,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) } protected override void OnModelCreating(ModelBuilder modelBuilder) - {} + { + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } } ", @@ -98,7 +102,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) } protected override void OnModelCreating(ModelBuilder modelBuilder) - {} + { + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } } ",