Entity Framework 4.1 - EFTracingProvider

前端 未结 3 631
迷失自我
迷失自我 2020-12-07 23:47

Is there a way to make the EFTracing provider work with EF 4.1?

EFTracing seems to need an objectcontext and I use dbcontext.

Thanks in advance!

3条回答
  •  甜味超标
    2020-12-08 00:32

    Whilst the previous answers work, I've found them problematic, a much simpler solution is to use the Clutch.Diagnostics.EntityFramework package from NuGet that uses MiniProfiler behind the scenes. It is significantly simpler to get working than EFTracingProvider, and a much more flexible solution.

    The project is on GitHub at https://github.com/Kukkimonsuta/Clutch

    For EFTracingProvider like functionality install the NuGet package and then implement IDbTracingListener like this:

    using System;
    using System.Data.Common;
    using System.Diagnostics;
    using Clutch.Diagnostics.EntityFramework;
    
    /// 
    /// 
    /// 
    public class DbTracingListener : IDbTracingListener
    {
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public void CommandExecuted(DbConnection connection, DbCommand command, object result, TimeSpan duration)
        {
            Debug.WriteLine(command.CommandText);
            Debug.WriteLine(string.Format("Executed in: {0}", duration));
        }
    
        /// 
        /// 
        /// 
        /// 
        /// 
        public void CommandExecuting(DbConnection connection, DbCommand command)
        {
    
        }
    
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public void CommandFailed(DbConnection connection, DbCommand command, Exception exception, TimeSpan duration)
        {
    
        }
    
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public void CommandFinished(DbConnection connection, DbCommand command, object result, TimeSpan duration)
        {
    
        }
    }
    

提交回复
热议问题