I'm trying to track down the cause of an Entity Framework InvalidOperationException
in an ASP.NET Core project. The exception suggests using DbContextOptionsBuilder.EnableSensitiveDataLogging
.
In my Startup.cs I have:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<TodoContext>(opt =>
{
opt.UseInMemoryDatabase("TodoList");
opt.EnableSensitiveDataLogging();
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
The problem is it doesn't seem to do anything. The exception message I get is exactly the same and still suggests using DbContextOptionsBuilder.EnableSensitiveDataLogging
.
Am I missing something?
I had the same problem. Solved it by using the OnConfiguring
method in the DbContext
itself, rather than the ConfigureServices
method in Startup
.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.EnableSensitiveDataLogging();
}
This option is documented here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With