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

标签 c# sqlite f# query-expressions

我正在使用 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

最佳答案

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

    static void Main(string[] args)
    {
        string sql = "select * from foo";
        SQLiteCommand command = new SQLiteCommand(sql, null);

        Console.WriteLine(command.CommandText);
        Console.ReadLine();
    }

也许您可以重新编写代码以利用它。

关于c# - 如何通过 System.Data.SQLite 检索 F# 查询表达式的 SQL 查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23996629/

相关文章:

ios - iOS 中 Sqlite 索引的使用

android - 用于任何 Activity 的静态数据库类

SQLite 和递归触发器

F#:是否有中缀运算符允许在后续 |> 上重用对象方法?

c# - 为什么 Marshal.Release 不对我的 COM 对象调用 Release?

C# 刷新 StreamWriter 和 MemoryStream

f# - 在 F# 中是否有等效的 C# 使用 T = X.Y.Z 导入指令?

f# - 任务并行库与异步工作流

c# - 将委托(delegate)传递给 WPF WebBrowser.InvokeScript 方法

c# - 调用方法并等待返回值