Find Out What Your Entity Framework Query Is Really Doing

Heitor Helmer Herzog
1 min readApr 4, 2019

--

You can turn on logging for your Entity Framework code by making some changes in your config file

Assuming that you’re using Entity Framework 6, you already have a logging tool that can give you some insights into the SQL your queries are generating and the time they take to run.

<interceptors>
<interceptor type=
"System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
<parameters>
<parameter value="C:\Logs\MyApp.txt"/>
</parameters>
</interceptor>
</interceptors>

Here’s what the output looks like:

Opened connection at 04-FEV-19 12:15:51 PM -05:00

SELECT 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 04-FEV-19 12:15:51 PM -05:00
-- Completed in 3 ms with result: SqlDataReader
Closed connection at 04-FEV-19 12:15:51 PM -05:00

--

--

Heitor Helmer Herzog
Heitor Helmer Herzog

Written by Heitor Helmer Herzog

Software developer, In love with games and the industry. Let’s code! About me: www.linkedin.com/in/heitorhherzog

No responses yet