Giorgi / EntityFramework.Exceptions

Strongly typed exceptions for Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql.
https://giorgi.dev/entity-framework/introducing-entityframework-exceptions/
Other
1.44k stars 68 forks source link

How can one use UseExceptionProcessor in code targetting multiple databases? #43

Closed derek-mba closed 2 years ago

derek-mba commented 2 years ago

In Startup.cs I have

        if (isPostGres)
        {
            services.AddDbContext<CprDbContext>(options => options
                .UseNpgsql(connection, x => x.UseNetTopologySuite())
                .UseExceptionProcessor(options);
            );
        }
        else
        {
            services.AddDbContext<CprDbContext>(options => options
                .UseSqlServer(connection, x => x.UseNetTopologySuite())
                .UseExceptionProcessor(options)
                );
        }

Obviously, this gives:

The call is ambiguous between the following methods or properties: 'EntityFramework.Exceptions.PostgreSQL.ExceptionProcessorExtensions.UseExceptionProcessor(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)' and 'EntityFramework.Exceptions.SqlServer.ExceptionProcessorExtensions.UseExceptionProcessor(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)' 

I could use AddInterceptors() rather than UseExceptionProcessor() if the interceptors were public, but since they aren't, how can I manage to accomplish this for a database determined purely by its connection string?

Giorgi commented 2 years ago

You can call UseExceptionProcessor as a static method.

derek-mba commented 2 years ago

Oh, of course. Sorry!