实体框架4.0:如何看SQL语句SaveChanges方法 [英] Entity Framework 4.0: How to see SQL statements for SaveChanges method

查看:188
本文介绍了实体框架4.0:如何看SQL语句SaveChanges方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前用的是context.Log用于跟踪的LINQ to SQL生成的SQL语句,如图<一href="http://stackoverflow.com/questions/11156124/sql-server-query-visualizer-cannot-see-generated-sql-query/11201832#11201832">Sql服务器查询可视化工具 - 无法看到生成的SQL查询

I used to use the context.Log for tracing LINQ to SQL generated SQL Statements as shown in Sql Server Query Visualizer – Cannot see generated SQL Query

context.Log = new OutputWindowWriter();

有关EF,有什么相似,容易像上面的方法呢?

For EF, is there anything similar and easy like the above approach?

推荐答案

在一般的,你可以连接内置的示踪剂,或通过简单的任何记录

In general you can hook up the built-in tracer or any logger by simple

context.Database.Log = msg => Trace.WriteLine(msg);

在的DbContext构造。 查看更多在 MSDN 。从MS其他的一些方法是这里(全部基于<一href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.log.aspx">DataContext.Log属性)。

in the DbContext constructor. See more in MSDN. Some other approaches from MS are here (all based on DataContext.Log property).

谈起由内特中提到的离合器的解决方案,它不与EF V6工作(见的这个错误报告

Talking about the Clutch solution mentioned by Nate, it doesn't work with EF v6 (see this bug-report).

参考

  1. 记录和拦截数据库操作(EF6起)
  2. 记录和拦截数据库操作
  1. Logging and Intercepting Database Operations (EF6 Onwards)
  2. Logging and Intercepting Database Operations

这篇关于实体框架4.0:如何看SQL语句SaveChanges方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆