.NET 7 console application using EF Core 7 why no OnConfiguring?

418 Views Asked by At

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?

2

There are 2 best solutions below

1
Guru Stron On BEST ANSWER

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:

0
Ali Safari On

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");
  }
}