Skip to content
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 CommandSource to CommandEventData #24421

Merged
merged 14 commits into from
Jul 28, 2021
Merged

Add CommandSource to CommandEventData #24421

merged 14 commits into from
Jul 28, 2021

Conversation

Giorgi
Copy link
Contributor

@Giorgi Giorgi commented Mar 16, 2021

This PR is my attempt to implement #23719

If the approach looks good I can fix the failing tests and add new ones for this feature.

@ajcvickers Thoughts?

@roji
Copy link
Member

roji commented Mar 17, 2021

I think some sort of tag mechanism for updates (#14078) would probably be more appropriate... This approach tells you that the command is coming e.g. from SaveChanges, but you still have no idea what is being changed and how. That seems to provide limited usefulness to interceptors and the like.

@Giorgi
Copy link
Contributor Author

Giorgi commented Mar 17, 2021

Tags for SaveChanges sounds useful but I think these are two different use cases. The scenario that I had in mind is that if you run a batch update with ExecuteSqlRaw it might be useful to differentiate between that and SaveChanges

@roji
Copy link
Member

roji commented Mar 17, 2021

Tags for SaveChanges sounds useful but I think these are two different use cases. The scenario that I had in mind is that if you run a batch update with ExecuteSqlRaw it might be useful to differentiate between that and SaveChanges

Wouldn't SaveChanges (and raw SQL) tags fulfill the same need? Also, assuming your application has many different things being executed by both SaveChanges and ExecuteSqlRaw, how useful is it to just know that something is SaveChanges or ExecuteSqlRaw?

@Giorgi
Copy link
Contributor Author

Giorgi commented Mar 17, 2021

I guess it would if you are writing the queries and the interceptors but if you are writing an interceptor for others to use you probably can't rely on tags being present.

@roji
Copy link
Member

roji commented Mar 17, 2021

I guess it's hard for me to imagine a generic interceptor (written for others) which cares specifically about whether a command comes from SaveChanges or ExecuteSqlRaw... Do you have any example in mind?

@Giorgi
Copy link
Contributor Author

Giorgi commented Mar 17, 2021

I wanted to process exceptions caused by ExecuteSqlRaw but IDbCommandInterceptor fires for both ExecuteSqlRaw and SaveChanges so I needed a way to find which one caused the interception to fire. For SaveChanges I use ISaveChangesInterceptor as it gives me access to the DbUpdateException to process. That's why I opened #24193

I guess it's a very specific use case but that's where the idea came from :)

@ajcvickers
Copy link
Member

@Giorgi I disagree with @roji here. I wanted this when I was writing an interceptor example for someone, and multiple customers have also asked for this. Tags for updates is also useful, but is overkill for many cases where I just need to know the event came from SaveChanges.

@ajcvickers ajcvickers self-assigned this Mar 19, 2021
@Giorgi
Copy link
Contributor Author

Giorgi commented Mar 19, 2021

@ajcvickers So should I implement tests for the new feature or do you want to discuss it first internally? Or maybe you want changes made to the way it is implemented?

Copy link
Member

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good; added some comments around avoiding breaking changes.

@Giorgi Giorgi marked this pull request as ready for review March 24, 2021 22:39
@Giorgi
Copy link
Contributor Author

Giorgi commented Mar 28, 2021

@ajcvickers The test failed because PassiveReaderCommandInterceptor is used in two different tests: one that uses FromSqlRaw and another uses LinqQuery. Should I create a separate interceptor for each case or do you have a better idea for testing this feature?

Copy link
Member

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Sorry for being so slow on this.

@Giorgi
Copy link
Contributor Author

Giorgi commented May 16, 2021

@ajcvickers Updated

@ajcvickers ajcvickers merged commit 85aaf40 into dotnet:main Jul 28, 2021
@ajcvickers
Copy link
Member

Thanks @Giorgi! Sorry for being so slow.

@Giorgi
Copy link
Contributor Author

Giorgi commented Jul 28, 2021

Thanks for merging @ajcvickers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants