Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework EF";“数据库优先”;ObjectContext和DbInterception?_Entity Framework_Entity Framework 6 - Fatal编程技术网

Entity framework EF";“数据库优先”;ObjectContext和DbInterception?

Entity framework EF";“数据库优先”;ObjectContext和DbInterception?,entity-framework,entity-framework-6,Entity Framework,Entity Framework 6,是否可以将EF 6.0的DbInterception与Database First ObjectContext一起使用?还是只通过DbContext使用 我无法让它与我的旧(遗留)ObjectContext一起工作 提前感谢,, ShlomiAFAIKDbInterception独立于您是使用数据库优先还是代码优先建模 您只需在应用程序的开始处添加一个拦截器 public class LogInterceptor : IDbCommandInterceptor { public void

是否可以将EF 6.0的DbInterception与Database First ObjectContext一起使用?还是只通过DbContext使用

我无法让它与我的旧(遗留)ObjectContext一起工作

提前感谢,,
Shlomi

AFAIK
DbInterception
独立于您是使用数据库优先还是代码优先建模

您只需在应用程序的开始处添加一个拦截器

public class LogInterceptor : IDbCommandInterceptor
{
    public void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
    {
    }

    public void NonQueryExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
    {
        System.Diagnostics.Debug.WriteLine(command.CommandText);
    }

    public void ReaderExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
    {
    }

    public void ReaderExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
    {
        System.Diagnostics.Debug.WriteLine(command.CommandText);
    }

    public void ScalarExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
    {
    }

    public void ScalarExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
    {
        System.Diagnostics.Debug.WriteLine(command.CommandText);
    }
}

嗨,谢谢你的回复,很抱歉我的回复迟了。我用普通ObjectContext(Db-First)尝试了这个方法,但没有成功。你知道为什么吗?(代码与您建议的非常相似)。
// Add an interceptor to log executed SQL queries.
DbInterception.Add(new LogInterceptor());