我正在使用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
答案 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();
}
也许您可以重新编写代码来使用它。