Skip to content

Commit

Permalink
Add partial method to the scaffolded DbContext
Browse files Browse the repository at this point in the history
fixes #12245
  • Loading branch information
Erik Ejlskov Jensen authored and ajcvickers committed May 8, 2019
1 parent cbefe76 commit 7343fa1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("}");
}

Expand Down Expand Up @@ -319,6 +326,13 @@ protected virtual void GenerateOnModelCreating(
}
}

_sb.AppendLine();

using (_sb.Indent())
{
_sb.AppendLine("OnModelCreatingPartial(modelBuilder);");
}

_sb.AppendLine("}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{}
{
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
",
Expand Down Expand Up @@ -98,7 +102,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{}
{
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}
",
Expand Down

0 comments on commit 7343fa1

Please sign in to comment.