老版本中: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());
注:
http://www.cnblogs.com/LingzhiSun/archive/2011/05/05/EF_Trick5.html
原文:http://www.cnblogs.com/i-blog/p/3513442.html