开发者

Getting a log of the SQL SubSonic is using

开发者 https://www.devze.com 2022-12-10 17:53 出处:网络
Linq2SQL has the great开发者_Go百科 Log property to see what the actual SQL statements that it is generating. Does SubSonic 2.2 have something similar to this?http://www.e-webdevelopers.com/268/view-t

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


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.


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.


It is not possible

0

精彩评论

暂无评论...
验证码 换一张
取 消