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. The Database property of your DbContext object has a Log property that will give you that information. To turn on logging, you just have to set the Log property to a method that will write to a log. This example sets up logging to write Entity Framework messages to to the Debug window:

Dim db As SalesOrderEntities
db = New SalesOrderEntities()
db.Database.Log = AddressOf Debug.WriteLine

In C#, you won't need the AddressOf keyword. You don't have to touch your code to make this 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.Infrastructure.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 the output looks like (slightly edited):

Opened connection at 08-Nov-16 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 08-Nov-16 12:15:51 PM -05:00
-- Completed in 3 ms with result: SqlDataReader
Closed connection at 08-Nov-16 12:15:51 PM -05:00

when I used the First method on one of my tables.

Find Out What Your Entity Framework Query Is Really Doing的更多相关文章

  1. 第三篇 Entity Framework Plus 之 Query Cache

    离上一篇博客,快一周,工作太忙,只能利用休息日来写一些跟大家分享,Entity Framework Plus 组件系列文章,之前已经写过两篇 第一篇 Entity Framework Plus 之 A ...

  2. 第二篇 Entity Framework Plus 之 Query Future

    从性能的角度出发,能够减少 增,删,改,查,跟数据库打交道次数,肯定是对性能会有所提升的(这里单纯是数据库部分). 今天主要怎样减少Entity Framework查询跟数据库打交道的次数,来提高查询 ...

  3. Entity Framework 6.0 Tutorials(2):Async query and Save

    Async query and Save: You can take advantage of asynchronous execution of .Net 4.5 with Entity Frame ...

  4. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库

    在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...

  5. 采用EntityFramework.Extended 对EF进行扩展(Entity Framework 延伸系列2)

    前言 Entity Framework 延伸系列目录 今天我们来讲讲EntityFramework.Extended 首先科普一下这个EntityFramework.Extended是什么,如下: 这 ...

  6. 重新认识了下Entity Framework

    什么是Entity Framework Entity Framework是一个对象关系映射O/RM框架. Entity Framework让开发者可以像操作领域对象(domain-specific o ...

  7. Entity Framework 6 Recipes 2nd Edition(9-4)译->Web API 的客户端实现修改跟踪

    9-4. Web API 的客户端实现修改跟踪 问题 我们想通过客户端更新实体类,调用基于REST的Web API 服务实现把一个对象图的插入.删除和修改等数据库操作.此外, 我们想通过EF6的Cod ...

  8. Entity Framework 6 Recipes 2nd Edition(13-2)译 -> 用实体键获取一个单独的实体

    问题 不管你用DBFirst,ModelFirst或是CodeFirst的方式,你想用实体键获取一个单独的实体.在本例中,我们用CodeFirst的方式. 解决方案 假设你有一个模型表示一个Paint ...

  9. Entity Framework 6 Recipes 2nd Edition(13-3)译 -> 为一个只读的访问获取实体

    问题 你想有效地获取只是用来显示不会更新的操作的实体.另外,你想用CodeFirst的方式来实现 解决方案 一个非常常见行为,尤其是网站,就是只是让用户浏览数据.大多数情况下,用户不会更新数据.在这种 ...

随机推荐

  1. SQL中几个常用的排序函数

         最近使用窗口函数的频率越来越高,这里打算简单介绍一下几个排序的函数,做一个引子希望以后这方面的问题能够更深入的理解,这里先简单介绍一下几个简单的排序函数及其相关子句,这里先从什么是排序开始吧 ...

  2. Salesforce Apex 使用JSON数据的示例程序

    本文介绍了一个在Salesforce Apex中使用JSON数据的示例程序, 该示例程序由以下几部分组成: 1) Album.cls, 定了了封装相关字段的数据Model类 2) RestClient ...

  3. 做了一个sublime text插件

    做了一个sublime text插件,可以方便地查看C++/python的调用图.插件的演示视频在这里: http://list.youku.com/albumlist/show?id=2820226 ...

  4. visual studio for mac的安装初体验

    微软2016 Connect 大会发布了visuo studio for mac的pre版本,由于工作原因,现在工作环境是mac,虽然开发现在是在用python,但一直关注着.net的发展,于是自己很 ...

  5. Windows Live Writer代码插件整理

    以下code插件命名按照 Windows Live Writer 中显示的插件名 1.Source code plug-in(cnblogs官方推荐) 界面: 效果: /** * Returns th ...

  6. OleDbDataReader快速数据读取方式

    查询得到OleDbDataReader后,有三种方式支持数据读取,如下: //方法一**速度中等 OleDbDataReader reader = command.ExecuteReader(); w ...

  7. bzoj 1061 志愿者招募 有上下界费用流做法

    把每一天看作一个点,每一天的志愿者数目就是流量限制,从i到i+1连边,上下界就是(A[i],+inf). 对于每一类志愿者,从T[i]+1到S[i]连边,费用为招募一个志愿者的费用,流量为inf.这样 ...

  8. Beta版本冲刺第三天

    Aruba 408 409 410 428 429 431 完成任务: 分类界面,实现手动新增/删除分类 分类界面,设置确定和取消按钮的intent 实现图片在编辑界面导入并合理摆放 立会照片: 燃尽 ...

  9. iOS - URL Scheme 操作

    推荐JLRoutes路由跳转 NSScanner 在寻找更加灵活的页面跳转和通知,我遇见了JLRoutes,从而学习使用URL Scheme来定义界面入口.以前从来没有使用过,不过很多大厂和流行的框架 ...

  10. 【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(二)

    Log4j 这个东西,大家都熟悉,就简单的介绍一下,算是一个抛砖引玉,因为我自己在Log日志的搭建方面,没有什么经验,但这东西确实是非常重要的,日后调Bug没有它基本不可能,如果有朋友有什么比较好的L ...