查看Entity Framework执行时生成的T-SQL语句
一种方法是使用SQL Server自带的SQL Profile工具。
另一种方法是:
protected void Page_Load(object sender, EventArgs e) { Response.Write(GetSQL()); } private string GetSQL() { Model1Container context = new Model1Container(); var result = from x in context.Actions where x.ID == 32 select x; var sql = ((System.Data.Objects.ObjectQuery)result).ToTraceString(); return sql.ToString(); }