Lerning Entity Framework 6 ------ Using a commandInterceptor
Sometimes, We want to check the original sql statements. creating a commandInterceptor is a good way to do this.
Add a class named MyCommandInterceptor
class MyCommandInterceptor: DbCommandInterceptor
{
public override void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
base.NonQueryExecuted(command, interceptionContext);
Console.WriteLine(command.CommandText);
}
public override void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
base.ReaderExecuted(command, interceptionContext);
Console.WriteLine(command.CommandText);
}
public override void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
base.ScalarExecuted(command, interceptionContext);
Console.WriteLine(command.CommandText);
}
}
The namespace System.Data.Entity.Infrastructure.Interception is needed. Then Add DbInterception.Add(new MyCommandInterceptor()); in your constructor of DbContext class:
public class MyDb:DbContext
{
public MyDb():base("name=TestDb")
{
DbInterception.Add(new MyCommandInterceptor());
}
public IDbSet<User> Users { get; set; }
}
It's all.
Lerning Entity Framework 6 ------ Using a commandInterceptor的更多相关文章
- Lerning Entity Framework 6 ------ Defining Relationships
There are three types of relationships in database. They are: One-to-Many One-to-One Many-to-Many Th ...
- Lerning Entity Framework 6 ------ Handling concurrency With SQL Server Database
The default Way to handle concurrency of Entity Framework is using optimistic concurrency. When two ...
- Lerning Entity Framework 6 ------ Working with in-memory data
Sometimes, you need to find some data in an existing context instead of the database. By befault, En ...
- Lerning Entity Framework 6 ------ Inserting, Querying, Updating, and Deleting Data
Creating Entities First of all, Let's create some entities to have a test. Create a project Add foll ...
- Lerning Entity Framework 6 ------ Defining the Database Structure
There are three ways to define the database structure by Entity Framework API. They are: Attributes ...
- Lerning Entity Framework 6 ------ Introduction to TPH
Sometimes, you have created two models. They have the same parent class like this: public class Pers ...
- Lerning Entity Framework 6 ------ Complex types
Complex types are classes that map to a subset of columns of a table.They don't contains key. They a ...
- Lerning Entity Framework 6 ------ A demo of using Entity framework with MySql
Create a new project named MySqlTest Install following packages by right-clicking on the References ...
- Lerning Entity Framework 6 ------ Joins and Left outer Joins
Joins allow developers to combine data from multiple tables into a sigle query. Let's have a look at ...
随机推荐
- sqlserver 数据迁移
转载地址: 1.https://blog.csdn.net/yh_zeng2/article/details/72901892 2.https://www.cnblogs.com/jpfss/p/91 ...
- linux挂载ntfs格式的硬盘
发生了一件辣眼睛的操作,一个现场应用升级,由于跨度很大,不敢直接动,就把现场的数据库dump拿回来,在公司做写升级测试. 于是,联系现场的工程师把数据库dump导出来,放到网盘弄回来. ------- ...
- 2018.11.01 bzoj4325: NOIP2015 斗地主(贪心+搜索)
传送门 原来一直以为是一道大模拟. 没想到是一道搜索+最优性剪枝 如何搜最优呢? 我们考虑怎么最快出完. 大概是应该尽量出当前能出出去最多的吧. 于是我们选择优先出顺子. 这样做有什么好处呢? 我们会 ...
- 走进JDK(三)------AbstractStringBuilder、StringBuffer、StringBuilder
AbstractStringBuilder是一个抽象类,StringBuffer.StringBuilder则继承AbstractStringBuilder,所以先说AbstractStringBui ...
- boost--asio
1.asio综述 asio的核心类是io_service,它相当于前摄器模式的Proactor角色,在异步模式下发起的I/O操作,需要定义一个用于回调的完成处理函数,当I/O完成时io_service ...
- s5-2 Cpu调度算法
调度程序采用什么算法选择一个进程(作业)? 如何评价调度算法的性能? 调度准则 CPU利用率 – 使CPU尽可能的忙碌 吞吐量 – 单位时间内运行完的进程数 周转时间 – 进程从提交到运行结束的全部时 ...
- innerText兼容处理
转载自:https://www.cnblogs.com/leejersey/p/3520497.html:稍微改了一下和加了一些注释: IE.Safari.Opera和Chrome支持innerTex ...
- C语言实现BMP图片生成
## #include <stdio.h> #include <stdlib.h> #include <string.h> typedef unsigned cha ...
- 使用 vs.php 调试PHP相关问题
1. 使用mysql_connect()方法时报错"Call to undefined function mysql_connect()" 这是由于在php.ini没有启用mysq ...
- 【python-selenium】python-selenium安装配置
selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于不同的语 ...