Getting a log of the SQL SubSonic is using

371 Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

It is not possible

2
On

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.

0
On

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.