Entity Framework 4.0: How to see SQL statements for SaveChanges method

后端 未结 6 708
长发绾君心
长发绾君心 2020-12-09 02:26

I used to use the context.Log for tracing LINQ to SQL generated SQL Statements as shown in Sql Server Query Visualizer – Cannot see generated SQL Query

conte         


        
6条回答
  •  北海茫月
    2020-12-09 02:47

    The Clutch.Diagnostics.EntityFramework (available in NuGet) works perfectly for me, and it's simpler than the EFTracingProvider.

    UPDATE for EF 6:

    Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application code. This is most commonly used for logging SQL, but can also be used to modify or abort the command.

    Specifically, EF includes:
    * A Log property for the context similar to DataContext.Log in LINQ to SQL.
    * A mechanism to customize the content and formatting of the output sent to the log.
    * Low-level building blocks for interception giving greater control/flexibility.

    See http://msdn.microsoft.com/en-US/data/dn469464

提交回复
热议问题