5

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

1 回答 1

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();
    }

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

于 2015-01-28T23:18:09.683 回答