SQLite 查询是“SELECT * FROM tblProducts WHERE Id = 1” 如何使用 Dapper 获取所有值的列表或具有属性和值的字典;
这是您可以尝试使用的代码片段,您可能需要更改您的查询。如果指定列名而不是 * 会更好。以下示例适用于字典。
public List<Dictionary<string, object>> GetProductValues()
{
const string connectionString = "Data Source=put_your_database_info";
const string query = "SELECT * FROM tblProducts WHERE Id = 1";
using (var connection = new SQLiteConnection(connectionString))
{
connection.Open();
var result = connection.Query(query);
var list = result.Select(row => (IDictionary<string, object>)row).ToList();
var dictionaryList = list.Select(dict =>
dict.ToDictionary(kvp => kvp.Key, kvvp => kvvp.Value)).ToList();
return dictionaryList;
}
}