How to view the SQL generated query by the Entity Framework


If we want to write log file of Entity Framework query in EF 6 we can follow this step

Step 1: Open EDMX cs file and copy the code:


  protected override void OnModelCreating(DbModelBuilder modelBuilder)  
     {  
       Database.Log = (query) => Debug.Write(query);  
     }  


Step 2 : write log on your Entity Framework query


  refauthrequests refauthEntity = EM_Refauthrequests.ConvertToEntity(vsspoAuditModel);  
       _db.refauthrequests.Add(refauthEntity);  
       _db.Database.Log = queryLog =>  
       {  
         Debug.Print(queryLog); // Debug.Print will show the output on visual studio output window You can write log using queryLog value  
       };  
       _db.SaveChanges();  


If you set debugger you will see the output window




Popular posts from this blog

mvc razor textboxfor change event change another textboxfor value

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report