Опитвам се да използвам Npgsql и/или Dapper за заявка към таблица и продължавам да се натъквам на Npgsql.PostgresException 42601: syntax error at or near "$1".
Ето какво имам, опитвайки го с NpgsqlCommand:
using (var conn = new NpgsqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["postgres"].ConnectionString))
{
conn.Open();
using (NpgsqlCommand command = new NpgsqlCommand("select * from Logs.Logs where Log_Date > current_date - interval @days day;", conn))
{
command.Parameters.AddWithValue("@days", days);
var reader = command.ExecuteReader();
Опитах го и с Dapper (моят предпочитан метод) с:
using (var conn = new NpgsqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["postgres"].ConnectionString))
{
conn.Open();
var logs = conn.Query<Log>("select * from Logs.Logs where Log_Date > current_date - interval @days day;", new {days = days});
Така или иначе получавам същото Npgsql.PostgresException 42601: syntax error at or near "$1" error.
Изявлението в изключението показва: select * from Logs.Logs where Log_Date > current_date - interval $1 day
Имайте предвид, че ако направя следното, работи добре, но не е правилно параметризирано:
var logs = conn.Query<Log>("select * from Logs.Logs where Log_Date > current_date - interval '" + days + "' day;");
какво правя грешно Оценявам много всяка обратна връзка. Благодаря ти.