public static string ToTraceString<T>(this IQueryable<T> t) { // try to cast to ObjectQuery<T> ObjectQuery<T> oqt = t as ObjectQuery<T>; if (oqt != null) return oqt.ToTraceString(); return string.Empty; }
For new EF 4.0 + way you will just have to invoke IQueryable<T> .ToString():
IQueryable<Customer> query = db.Customers.Where(c=> c.CustomerName.Contains("a")).AsQueryable(); Console.WriteLine(query.ToString());
Simple! Just like that!