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

hook option to check how many times a sql query is run #12

Open
chinwobble opened this issue Mar 19, 2017 · 3 comments
Open

hook option to check how many times a sql query is run #12

chinwobble opened this issue Mar 19, 2017 · 3 comments
Labels

Comments

@chinwobble
Copy link

hi,

Is there a way to use this to check how many times a dbContext asks the database for data?
In my integration tests I want to assert that the data access method only asks for data once or twice.

I was hoping for a non generic version of the onLoad method?

@dombrovsky
Copy link
Owner

Hi.
You may do your own IDbHook implementation, for example:

class IncrementDataAccessCountHook : IDbHook
    {
        public void HookEntry(IDbEntityEntry entry)
        {
            entitiesMaterializedCount++;
        }
    }

and attach it using non generic OnLoad

dbContext.OnLoad().Attach(new IncrementDataAccessCountHook())

You may achieve the same by using generic OnLoad specifying object as a generic type.

@chinwobble
Copy link
Author

hi @dombrovsky ,

Thanks for the prompt reply and excellent library.
However i tried this and it looks like it only tells me how many entities are being tracked by the DB context as the hook is being called for every single entry rather than DB call.

@dombrovsky
Copy link
Owner

Yes, load hooks are fired for each entity object when created from data in the data source as part of a query or load operation (as it based on ObjectMaterialized event).

If you need to count number of individual queries to database, that is something outside of the scope EntityHooks can help with.
However I recommend looking into EF interceptions. Look at this tutorial for details.

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

No branches or pull requests

2 participants