asp.net mvc - Logging SQL statements of Entity Framework 5 for database-first aproach -


i'm trying use entity framework tracing provider log sql staments generated.

i changed context class this:

public partial class mydbcontext: dbcontext {      public mydbcontext(string nameorconnectionstring)     : base(eftracingproviderutils.createtracedentityconnection(nameorconnectionstring), true) {     // enable sql tracing     ((iobjectcontextadapter) this).objectcontext.enabletracing(); }      protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         throw new unintentionalcodefirstexception();     }      //dbsets definition.... } 

but doesn't log sql statements on output window...

should had more in class or in web.config file? (i'm working on asp.net mvc 4 project)

i using solution in following post:entity framework 4.1 - eftracingprovider

but made changes don't know if important:

the class partial instead of abstract, , constructor public instead of protected...

what missing?

after modifying code, need enable tracing in web.config 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 tracesource should context name prefixed 'entityframework'. make sure disable tracing when deploy application production setting switchvalue off.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -