且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ServiceStack OrmLite Sql 查询日志记录

更新时间:2023-02-05 16:07:52

您需要 OrmLite 的调试版本才能查看 SQL 输出.您可以通过其他几种方式查看最后一条 sql:

You would need the debug build of OrmLite to see the SQL output. There are a couple of other ways you can view the last sql:

Console.WriteLine(dbCmd.GetLastSql());

您还可以通过设置连接过滤器来分析数据库连接,您可以这样做:

You can also profile the db connection by setting a connection filter, which you can do with:

var dbFact = new OrmLiteConnectionFactory(
   "Data Source={0};Version=3;".Fmt(dbFileName), true, 
   SqliteOrmLiteDialectProvider.Instance) {
   ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
};

如果您在 ServiceStack 中运行它,您将看到所有 SQL 语句的分析计时输出.此处提供了一个示例:

Which if you ran this in ServiceStack will let you see the profiled timing outputs of all the SQL statements. An example of what this looks like is available here:

https://gist.github.com/1787443