我正在尝试使用 dapper 来参数化我编写的用于更新插入的 postgres 匿名函数。这是代码:
private static int UpsertProductPrice(
IDbConnection connection,
Data.ProductPrice price,
List<Data.ProductPriceTier> priceTiers)
{
string postgres = @"DO $$
BEGIN
UPDATE product_price
SET start_date = @StartDate, end_date = @EndDate, price_tier_type = @PriceTierType
WHERE product_price_external_id = @Id;
IF found THEN
RETURN;
END IF;
BEGIN
INSERT INTO product_price(product_price_external_id, start_date, end_date, price_tier_type)
VALUES (@Id, @StartDate, @EndDate, @PriceTierType);
RETURN;
EXCEPTION WHEN unique_violation THEN END; END$$;";
int productPriceId = connection.Execute(
postgres,
new { Id = price.product_price_external_id, StartDate = price.start_date, EndDate = price.end_date, PriceTierType …Run Code Online (Sandbox Code Playgroud)