locked
How to map a SQL Query to a Linq query RRS feed

  • Question

  • Hello,

     

    I would like to be able to map a SQL query, as received by SQLServer to the originating Linq query.

     

    On SQLServer, we register all SQL queries with a duration of more than 10 seconds. We use this list to check if there are no queries to optimize. With queries that are created directly in the code, it's easy to find where the query is sent to SQLServer and to find which screen of the application is impacted. I would like to do the same with Linq queries.

     

    Is it possible to find, starting from a SQLQuery, which Linq query produced it?

     

    Thanks in advance.

    Thursday, August 28, 2008 8:43 AM

Answers

  • Interesting request.  My DBA hasn't hit me up just yet, but I suspect this will occur one day.

     

    Perhaps there's a way to embed a comment in the SQL that gets generated by LINQ to provide a clue as to the originating class and method, but I'm not sure if this is possible.

     

    Another approach is to enable logging in your app server to record method call entries and exits.  This could then be correlated to the timestamp of a SQL trace.  But the app server code needs to be enabled for this.

     

    -Larry

     

    Friday, August 29, 2008 1:57 AM

All replies

  • Interesting request.  My DBA hasn't hit me up just yet, but I suspect this will occur one day.

     

    Perhaps there's a way to embed a comment in the SQL that gets generated by LINQ to provide a clue as to the originating class and method, but I'm not sure if this is possible.

     

    Another approach is to enable logging in your app server to record method call entries and exits.  This could then be correlated to the timestamp of a SQL trace.  But the app server code needs to be enabled for this.

     

    -Larry

     

    Friday, August 29, 2008 1:57 AM
  • Lazy loading of associations and group results will complicate this further.
    Friday, August 29, 2008 3:53 AM