-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add virtual methods to existing interceptor base classes #28516
Comments
@frandazzo The method is defined in the interface, and not implemented by the abstract base class. This means it can't be overridden, merely implemented, and hence should have the @dotnet/efteam Where we have existing abstract base types as well as interfaces with default implementations, should we consider adding methods to the abstract base types to avoid this confusion? It's also interesting that it is now very easy to add a method that, accidentally, does not implement a method from the interface. This is, I believe, why override is required in C# when overriding a virtual method--I remember it making it better than some other languages, possibly Java, in this respect. |
Ok i've removed the override keyword but if i try to debug the interceptor method, nothing happens. It seems like no interceptor was added or that the ConnecitonCreating Method is not called. |
Moreover this ticket #23087 was closed stating that it was implemented from version 6 |
@frandazzo You're right; this doesn't work unless the interface is implemented explicitly as well as inheriting from the base class: ConnectionInterceptor : DbConnectionInterceptor, IDbConnectionInterceptor I will discuss with the team. |
Thank you @ajcvickers ; return InterceptionResult.SuppressWithResult(new is an exmple of what i have in mind. thank you in advance |
@frandazzo Please post the exception message and stack trace. |
Why the ensureCreated does not work (with the interceptor)? |
Ok probably the problem is due to the attempt to open the connection for a not yet existing db. There is a workaround? |
@frandazzo When EnsureCreated needs to create a database, it does so by opening a connection to the "master" database on the server for which the database needs to be created. (Since it can't open a connection to a database that doesn't exist.) Your code is blindly replacing that with a connection to the database that does not exist, and hence it is failing. You need to be more selective about when you replace the connection so that the connection to the master database is not replaced. The connection string can be obtained from, Note for triage: we should make the |
@ajcvickers Thank you for your answer. Unfortunately i've found no way to use interceptors to pass a connection fatory to the dbcontext. |
…s using default member implementations Fixes #28516
In the code snippet below is not possible to override the ConnectionCreating method.
Attached is a simple project test that cannot compile. If removing the override keyword the project compiles but the overload is obviously ignored.
WebApplication1.zip
EF Core version: 7
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 7.0)
Operating system: windows
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: