简体   繁体   English

ServiceStack OrmLite Sql查询日志记录

[英]ServiceStack OrmLite Sql Query Logging

As per the Service Stack Ormlite documentation . 根据Service Stack Ormlite文档 I should generate the sql query in debug mode. 我应该在调试模式下生成sql查询。 But, I am not able to see those queries. 但是,我无法看到这些疑问。 Simple code 简单的代码

 private static readonly string DataDirLoc =
        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
        "\\TargetIntegration\\Test\\Debug\\";



    private readonly string dbFileName = DataDirLoc +
                                              "Test.db3";

    [Test]
    public void Can_Generate_log() {
        //var writer = new TextWriterTraceListener(System.Console.Out);
        //Debug.Listeners.Add(writer);
        Debug.Write("this is a try");
        var dbFact = new OrmLiteConnectionFactory("Data Source={0};Version=3;".FormatParams(dbFileName), true,
                                                  SqliteOrmLiteDialectProvider.Instance);
          IDbConnection dbConnection = dbFact.OpenDbConnection();
       var dbCommand = dbConnection.CreateCommand();
        dbCommand.CreateTable<Contact>();
    }

You would need the debug build of OrmLite to see the SQL output. 您需要OrmLite的调试版本才能看到SQL输出。 There are a couple of other ways you can view the last sql: 您还可以通过其他几种方式查看最后一个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)
};

Which if you ran this in ServiceStack will let you see the profiled timing outputs of all the SQL statements. 如果您在ServiceStack中运行它,将允许您查看所有SQL语句的配置文件定时输出。 An example of what this looks like is available here: 这里有一个例子可以在这里找到:

https://gist.github.com/1787443 https://gist.github.com/1787443

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM