I’m working in WPF with C# and Postgres.
I’m running this query:
public static int GetOfflineDiscountCount(string discountHashId, string loyaltyCustomerId)
{
// Initialize the count variable
int discountCount = 0;
Console.WriteLine($"Customer ID: {loyaltyCustomerId}, Discount ID: {discountHashId}");
try
{
using (var dbContext = new XXXX(ConnectionStringHelper.posConnectionString))
{
var query = @"
SELECT COUNT(tsd.id) AS countAll
FROM XXXX.tmp_sale_discount tsd
JOIN XXXX.tmp_sale_items tsi ON tsi.id = tsd.sale_item_id
JOIN XXXX.tmp_sale ts ON ts.id = tsi.sale_id
WHERE ts.send_status != 1
AND ts.customer_id = @p0
AND tsd.discount_id = @p1";
// Execute the query with parameters
discountCount = dbContext.Database.SqlQuery<int>(
query,
new Npgsql.NpgsqlParameter("@p0", loyaltyCustomerId), // Parameter for
customer_id
new Npgsql.NpgsqlParameter("@p1", discountHashId) // Parameter for
discount_id
).FirstOrDefault();
Console.WriteLine($"{discountCount}");
}
}
catch (Exception ex)
{
LogHelper.WriteException(ex);
}
// Return the final count
return discountCount;
}
When I set in static values it’s returning a 0 count. however when I’m running the query modified to work directly with my PGAdmin and the same variables it’s working fine.
I have made sure that the DB connection is good, performing as intended. I’ve BLOCKED the connection to the cloud server to preserve the DB Values I wanted as a trigger, but this is only being run on the Local Copy of the DB, not the Cloud version.
When in the program, the variables for the loyaltyCustomerId
and discountHashID
are correct.
Not sure what I’m wrong wrong here.
2