EF-查看生成的SQL语句

老版本中:EF 4和EF 3.5 SP1

using (var context = new TestDBEntities())
{
var query = from p in context.Parents
where p.Name == "Lingzhi"
select p; ObjectQuery<Parent> parents = query as ObjectQuery<Parent>;
if (parents != null)
{
string sql = parents.ToTraceString();
}
}

EF4.1及其以上:

            LckDbContext ef = new LckDbContext();
var personInfo = from a in ef.Persons.Include("Photo")
select a;
Console.WriteLine(personInfo.ToString());

注:

  • 以上方法在Linq语法时支持友好,但在Lamda函数式查询时不是很好。
  • 其他方式,SqlServer中可以用SQL Server Profiler监控等

http://www.cnblogs.com/LingzhiSun/archive/2011/05/05/EF_Trick5.html

上一篇:给Eclipse设置android的SDK位置时,出现这个:This Android SDK requires Andr...ate ADT to the latest


下一篇:【边做项目边学Android】小白会遇到的问题--This Android SDK requires Android Developer Toolkit version 23.0.0 or above