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

后端 未结 6 722
长发绾君心
长发绾君心 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:46

    In general you can hook up the built-in tracer or any logger by simple

    context.Database.Log = msg => Trace.WriteLine(msg);
    

    in the DbContext constructor. See more in MSDN. Some other approaches from MS are here (all based on DataContext.Log property).

    Talking about the Clutch solution mentioned by Nate, it doesn't work with EF v6 (see this bug-report).

    REFERENCES

    1. Logging and Intercepting Database Operations (EF6 Onwards)
    2. Logging and Intercepting Database Operations

提交回复
热议问题