-
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
Possible to get statistics back for DbContext.SaveChanges? #10319
Comments
@joshmouch We discussed this and we don't have any really good answers. It seems to us that overriding SaveChanges and issuing the commands is probably the best way to go--yes there will be some additional overhead, but collecting the statistics is also adding overhead, and we're expecting this is done in dev/debug anyway. I'm not sure how you would get the statistics back, but you can use the underlying SqlConnection object after SaveChanges to query the database for whatever is needed, so if you figure out how to do this outside of EF, then the same thing should work with EF. |
Greetings @ajcvickers, I've attempted to do something similar to the OP by implementing IDbCommandInterceptor within EF Core. However, despite how I have attempted to attach to the connection's InfoMessage event, I cannot seem to receive the events themselves. I've dumbied up a simple app to confirm that it should work as I had expected outside of EF Core. This seems to follow your stated principle of "what should work outside EF Core, should work inside". Have I overlooked something in my implementation or expectations? `
` Thanks for any assistance you may offer. Kind regards & Happy Thanksgiving, |
Similarly, I attempted to implement an IDbConnectionInterceptor and none of the methods on it are being called, including:
|
@windhandel this issue is from 2017 and things have changed since - can you please open a new issue with a code sample where you use IDbConnectionInterceptor? That approach should work. |
Please see the new issue I created for the workaround for EF Core correctly causing the SqlConnection's InfoMessage event to be fired. |
I'd like to write some automated tests to measure how much database IO is occurring during particular processes in our application and ensure they never go above a certain threshold.
Outside of EF, you would:
So I'm wondering if there is some way to get these same measurements as part of the call to DbContext.SaveChanges. I think you could override the SaveChangesAsync and SaveChanges methods to execute the "set io statistics" statement, but doing it that way would result in an extra database hit and also I wouldn't know how to get the statistics back after SaveChangesAsync was complete.
Any thoughts or ideas?
The text was updated successfully, but these errors were encountered: