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

时间:2014-06-02 14:12:24

标签: 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

1 个答案:

答案 0 :(得分:0)

SQLiteCommand对象具有相关的CommandText属性。

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

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

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