实体框架中的往返日志记录
我知道这在 Linq-to-Sql 中是可能的,是否可以自动记录通过实体框架中的特定 ObjectContext 进行的所有查询?我特别对 ObjectContext 生命周期中运行的查询数量感兴趣。
I know this is possible in Linq-to-Sql, is it possible to automatically log all queries made through a particular ObjectContext in entity framework? In particular, I'm interested in the number of queries that are run in the lifetime of the ObjectContext.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 ObjectQuery.ToTraceString 或查看 Jaroslaw Kowalski 的跟踪和缓存提供程序
You can use ObjectQuery.ToTraceString or look into Jaroslaw Kowalski's tracing and caching provider
看起来您正在寻找快速且易于实现的东西,而不是必须将日志语句或其他代码插入到所有查询例程中。我不知道如何仅使用 ObjectContext 实例来执行此操作,但可能有一种方法可以通过您的数据提供程序来执行此操作。例如,如果您碰巧使用 Devart for Oracle,则可以处理 Devart.Common.DbMonitor 的 Devart.Common.DbMonitor.TraceEvent 事件。
It seems like you're looking for something quick and easy to implement, rather than having to insert log statements or other code into all of your query routines. I don't know of a way to do this with just an instance of ObjectContext but there may be a way to do it through your data provider. For example if you happen to be using Devart for Oracle, you can handle the Devart.Common.DbMonitor.TraceEvent event of Devart.Common.DbMonitor.