Log,SqlServerProfile, EFProfile三种监视EntityFramework中的sql流

大家在学习entityframework的时候,都知道那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 formatt

你可能感兴趣的:(最高笔记,笔记,sql,sqlserver,数据库)