question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data store command interception

See original GitHub issue

Is there any extensible point on where EF hits the db, something that can be overridable to log or do anything everytime a hit to the db.

im wondering of something like

override OnDatabaseHit(Operation op, Context context) {
     if (typeof(op) == Query | SaveChanges | ... {
         Console.WriteLine(context.Query)
     }
}

if not, take it as a suggestion for EF7 😃

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tourilicommented, Jun 29, 2018

Hi there What about Intercepting connection level to support Row Level Security. I checked the latest release, but still not supported yet. I’m working around this lack by connecting the legacy handler Database.GetDbConnection().StateChange to monitor the connection state in order to inject my session context:

this.Database.GetDbConnection().StateChange += (s, e) =>
{
    if (e.OriginalState != System.Data.ConnectionState.Open && e.CurrentState == System.Data.ConnectionState.Open)
    {
        DbCommand cmd = this.Database.GetDbConnection().CreateCommand();
        cmd.CommandText = "EXEC sp_set_session_context @key=N'ObjectId', @value=@UserId";
        ....
    }
};

on a derived DbContext constructor.

I would like to see a better approach using DI to pipe this injection? Thanks

0reactions
wpostmacommented, Jun 6, 2016

I put a question on stack-overflow to seek alternative techniques for EF Core.

http://stackoverflow.com/questions/37660746/can-i-configure-an-interceptor-yet-in-entityframework-core

Instead of a heavyweight framework approach perhaps whatever replaces interceptors could be a very lightweight and simple pattern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ArcGIS Data Store command utility reference—ArcGIS ...
This utility is used with relational, tile cache, and spatiotemporal big data stores and graph stores. If you need to create a relational...
Read more >
Interceptors - EF Core
Interception for database operations and other events.
Read more >
Entity Framework 6, Command Interception & Stored ...
You can always use Context Log property for intercepting any of the DB queries fires using DataContext. You can define a constructor on...
Read more >
SYSMSGS Command: Intercept Messages - TechDocs
The SYSMSGS command intercepts any message while it is being written to the JES system message data set belonging to an individual JOB...
Read more >
intercept | Cypress Documentation
Spy and stub network requests and responses.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found