大家在学习entityframework的时候,都知道那linq写的叫一个爽,再也不用区分不同RDMS的sql版本差异了,但是呢,高效率带来了差灵活性,我们无法控制sql的生成策略,所以必须不要让自己缺乏好的工具去监控sql,本篇给大家介绍的三种监控手段Log和SqlServer ...
大家在学习entityframework的时候,都知道那get='_blank'>linq写的叫一个爽,再也不用区分不同RDMS的sql版本差异了,但是呢,高效率带来了差灵活性,我们
无法控制sql的生成策略,所以必须不要让自己缺乏好的工具去监控sql,本篇给大家介绍的三种监控手段Log和SqlServer profile,ef profile。。。
一:Log监控
这个属于entity framework自带的一个Action方法,它给大家带来了不错的用户体验,我们可以将其输出放到控制台,又或者写入到记事本中。。。这
里我就通过EDM来生成codefirst,可以看到如下的Database的Log定义,然后大家就可以给他灌入一个带string参数的Action方法,比如Console.WriteLine。
// // 摘要: // Set this property to log the SQL generated by the System.Data.Entity.DbContext // to the given delegate. For example, to log to the console, set this property // to System.Console.Write(System.String). // // 备注: // The format of the log text can be changed by creating a new formatter that derives // from System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter and // setting it with System.Data.Entity.DbConfiguration.SetDatabaseLogFormatter(System.Func{System.Data.Entity.DbContext,System.Action{System.String},System.Data.Entity.Infrastructure.Interception.DatabaseLogFormatter}). // For more low-level control over logging/interception see System.Data.Entity.Infrastructure.Interception.IDbCommandInterceptor // and System.Data.Entity.Infrastructure.Interception.DbInterception. public Action<string> Log { get; set; }
原标题:监视EntityFramework中的sql流转你需要知道的三种方式Log,SqlServerProfile, EFProfile
关键词:sql
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。