Posts Tagged ‘ObjectQuery’

How do I view the SQL generated by the entity framework?

var result = from x in appEntities
             where = 32
             select x;

var sql = ((System.Data.Objects.ObjectQuery)result).ToTraceString();


I create a extension…

public static class IQueryableExtension
     public static String ToTraceSQL(this IQueryable obj) 
         return ((System.Data.Objects.ObjectQuery)obj).ToTraceString();

Using this:

var iQuerableResult = dataBase.BiServico.Take(10);
string myResustSQL = iQuerableResult.ToTraceSQL();

Shazan! =)

hope I have helped!