Entity framework EF";“数据库优先”;ObjectContext和DbInterception?
是否可以将EF 6.0的DbInterception与Database First ObjectContext一起使用?还是只通过DbContext使用 我无法让它与我的旧(遗留)ObjectContext一起工作 提前感谢,,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
ShlomiAFAIK
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());