Thursday, August 10, 2017

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.Database.Log = queryLog =>  
         Debug.Print(queryLog); // Debug.Print will show the output on visual studio output window You can write log using queryLog value  

If you set debugger you will see the output window

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...