none
How do i log DML Statements Generated by the Entities Framework after calling SaveChanges() RRS feed

  • Question

  •  

    Hi,

     

    i want to log the Dml statements which have been generated while calling SaveChanges().

     

    How do i do this.

     

    any help is appreciated.

     

     

    Thursday, June 12, 2008 11:26 AM

Answers

  • Entity Framework V1 does not directly support tracing API for updates.

     

    For queries you can use ToTraceString() on your ObjectQuery<T> to get the query text, but there is no such option for update. For debugging, we recommend using SQL Profiler.

     

    There is one advanced technique that you may be interested in: It is possible to do tracing at the provider level. Given that Entity Framework provider interface is public (see http://code.msdn.microsoft.com/EFSampleProvider) it is possible to write an intercepting provider that sits in between EF and the provider of choice and logs all commands to some output. I have written such tracing provider for EF V1 and I'm planning to publish it on MSDN code gallery along with a series of blog posts that explain the technique.

     

    From the usage standpoint, you will be able to subscribe to an event that will be raised whenever store command is executed and you will have access to the command and its parameters. All you have to do for it to work is to modify your app.config and/or connection string and SSDL file.

     

    Stay tuned - this will be published relatively soon.

    Thursday, June 12, 2008 1:36 PM
    Moderator