Logging SQL statements of Entity Framework 5 for database-first aproach

前端 未结 1 1258
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 03:50

I\'m trying to use Entity Framework Tracing Provider to log the SQL staments generated.

I changed my context class to something like this:

public par         


        
相关标签:
1条回答
  • 2021-01-17 04:17

    After modifying your code, you need to enable tracing in your web.config like this:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.diagnostics>
        <sources>
          <source name="EntityFramework.NorthwindEntities" switchValue="All" />
        </sources>
      </system.diagnostics>
    </configuration>
    

    The name of your TraceSource should be your context name prefixed with 'EntityFramework'. Make sure that you disable tracing when you deploy your application to production by setting the switchValue to Off.

    0 讨论(0)
提交回复
热议问题