views:

70

answers:

2

Is there a way to extract the SQL which is run against the database from a bit of subsonic? For instance I have

foreach (var item in EVT.All().Where(e => e.EVT_USRNAME == "stimms"))
        {
         ...
        }

Can I get at what is run?

+1  A: 

In Subsonic, you can get the command which will be executing against a query in this way:

IQueryable query = EVT.All().Where(e => e.EVT_USRNAME == "stimms");
SubSonic.Linq.Structure.DbQueryProvider provider = (SubSonic.Linq.Structure.DbQueryProvider)query.Provider;
string command = provider.GetCommand(query.Expression).CommandSql;
Yogesh
Yep that works, now I can see what I need to do. Thanks
stimms
A: 

Simon, Another method that requires more under-hood revelation is to debug the Subsonic source-code. Set a breakpoint at your query, watch the evaluated statement, and look for the QueryText property.

MAbraham1

MAbraham1