Assuming that your ' re using Entity Framework 6, you already has a logging tool that can give you some insights into the SQ L your queries is generating and the time they take to run. The Database property of your DbContext object have a Log property that would give you that information. To turn on logging, you just has the to set the Log property to a method of that would write to a Log. This example sets-logging to-write Entity Framework messages to the Debug window:
Dim db as Salesorderentitiesdb = New salesorderentities () db. Database.Log = AddressOf Debug.WriteLine
In C #, you won ' t need the ADDRESSOF keyword. You do not have the to touch your code to make the change and you can also write your output to file by making some changes in your config file. To turn on logging to a file from your config file, just add a reference to the Databaselogger in the SYSTEM.DATA.ENTITY.I Nfrastructure. Interception namespace and point it to a file with XML, like this:
<interceptors> <interceptor type= " System.Data.Entity.Infrastructure.Interception.DatabaseLogger, entityframework "> <parameters> <parameter value= "C:\Logs\MyApplication.txt"/> </parameters> </interceptor></ Interceptors>
Here's what's the output looks like (slightly edited):
Opened connection at 08-nov-16 12:15:51 pm-05:00select TOP (1) [c].[ ID] as [id], [c].[ FirstName] As [FirstName], [c].[ LastName] As [LastName], [c].[ Custcreditstatus] As [Custcreditstatus], [c].[ Creditlimit] As [Creditlimit], [c].[ Renewaldate] As [renewaldate], [c].[ Valid] as [Valid] from [dbo].[ Customers] as [c]--executing at 08-nov-16 12:15:51 pm-05:00--completed in 3 ms with result:sqldatareaderclosed Connect Ion at 08-nov-16 12:15:51 pm-05:00
When I used the first method on one of my tables.
Find Your Entity Framework Query is really Doing