1

I built a database first .NET 7 and EF Core 7 application and used the EF Power Tools to create the context and model classes. I keep reading about OnConfiguring() being in the context class. I only have OnModelCreating()? What did I do wrong?

Thanks, Doug

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AeroClassics
  • 1,074
  • 9
  • 19

2 Answers2

2

Nothing. You can still override DbContext.OnConfiguring in your context if you want to but with modern patterns using DI it is rarely needed (unless you are using something like interceptors).

See also:

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • 1
    Thanks. I shall read that. I reran the Power Tools and checked the box concerning the connection string. I now have a connections and a OnConfiguring(). – AeroClassics May 22 '23 at 20:01
1

As @Guru Stron said above, you haven't done anything wrong!

if you do need to provide additional configuration options for your context, you can override the DbContextOptionsBuilder in the OnConfiguring() method.

For example:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
if (!optionsBuilder.IsConfigured) {
    optionsBuilder.UseSqlServer("connection-string-placeholder");
  }
}
Ali Safari
  • 1,535
  • 10
  • 19