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