dotnet / dotnet/EntityFramework.Docs

Interceptor methods or events for query start/query consumed

Open
#3,905 6 comments 0 reactions 0 assignees View on GitHub
area-interceptors
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

One of the things I like to try to track during development is the time it takes to materialize and track objects that are returned by a query. The reason I do this is because I have some clients who insist on returning many thousands of rows from a query. They run the query in SSMS and say, "See, it only takes x milliseconds for the query to run, so why does the screen take y seconds to appear?" (or questions along those lines).

If I could intercept when entity materialization starts and stops, as well as when change tracking starts and stops, I could show clients a more complete idea of how long it takes the query to execute in its entirety. I could also easily catch instances in which I might be returning too much data for other reasons.

By extending my DbContext class and handling its ChangeTracker.Tracked event, I've been able to more or less time how long it takes to add objects to the change tracker. But, the hack I came up with is less than elegant. And, it doesn't take into account the overhead required to materialize objects at all.

If this were something that could easily be put into the code base, it would be of benefit to me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.