views:

121

answers:

3

Linq2SQL has the great Log property to see what the actual SQL statements that it is generating. Does SubSonic 2.2 have something similar to this?

+1  A: 

http://www.e-webdevelopers.com/268/view-the-sql-generated-by-subsonic/

SqlQuery sq = new Select()
                   .From(Item.Schema)
                   .InnerJoin(ItemStatus.IstIDColumn, Item.ItmStatusColumn)
                   .InnerJoin(ItemCategory.ItcItemIDColumn, Item.ItmIDColumn)
                   .WhereExpression("ItmIsEnabled").IsEqualTo(true)
                   .AndExpression("ItmName").Like("%" + findThis + "%")
                   .Or(Item.ItmShortDescriptionColumn).Like("%" + findThis + "%")
                   .Or(Item.ItmItemCodeColumn).Like("%" + findThis + "%")
                   .Or(Item.ItmLongDescriptionColumn).Like("%" + findThis + "%")
                   .Paged(pageIndex, PageSize)
                   .OrderAsc("itmName");

          Response.Write(sq.ToString());

Not tested as I'm not infront of my dev box. Hope that helps.

Pino
The problem with this means finding every query and adding a line next to it to do the logging. What I was hoping for was a universal system I can subscribe to similar to how Linq2SQL has.
Robert MacLean
I dont think Subsonci supports that at present. Maybe add it in ;)
Pino
A: 

SubSonic 2.2 ActiveRecord has some events you can override, like AfterValidate() and BeforeCommit(). You could use one of those to log the Sql, but you would have to modify your templates so that code ended up in all your classes.

Or just hit up SubSonic\DataProviders\DataService.cs in your local SubSonic source and see if it will work to add your logging events to all of the .Execute* methods.

ranomore
A: 

It is not possible

Robert MacLean