相关疑难解决方法(0)

Dapper 参数无法通过 npgsql 连接与 PostgreSQL 一起使用,postgres 匿名函数参数化是否支持?

我正在尝试使用 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)

c# postgresql npgsql dapper

5
推荐指数
1
解决办法
3676
查看次数

标签 统计

c# ×1

dapper ×1

npgsql ×1

postgresql ×1