如何通过System.Data.SQLite检索f#查询表达式的SQL查询字符串

本文关键字:查询 查询表 表达式 SQL 字符串 System 何通过 Data SQLite 检索 | 更新日期: 2023-09-27 18:06:18

我正在使用System.Data.SQLite,我正在尝试检索由下面的查询表达式生成的SQL字符串。查询执行正确,但是SQL字符串是SELECT NULL AS [EMPTY]

似乎不支持GetCommand().CommandText,但如果是这样,如何才能访问生成的SQL字符串?

[<Test>]
member this.showSQL() =
    let connectionString = sprintf @"Data Source=%s;UTF8Encoding=True;Version=3" dbFilename
    let connection = new SQLiteConnection(connectionString)
    use dc = new DataContext(connection)
    let channelMap = dc.GetTable<ChannelData>()
    let map = query {
        for row in channelMap do
        where (row.ChannelId = 1)
        select (row.ChannelId, row.Data0, row.State) }
    let cmd = dc.GetCommand(map).CommandText;
    printf "SQL: %s" cmd

如何通过System.Data.SQLite检索f#查询表达式的SQL查询字符串

SQLiteCommand对象有关联的CommandText属性按预期工作。

    static void Main(string[] args)
    {
        string sql = "select * from foo";
        SQLiteCommand command = new SQLiteCommand(sql, null);
        Console.WriteLine(command.CommandText);
        Console.ReadLine();
    }

也许你可以重新编写你的代码来利用它