Я пытаюсь вызвать хранимую процедуру, используя ядро .net.
У меня была Эта проблема. После исправления моей предыдущей проблемы у меня есть другая синтаксическая ошибка.
PostgresException: 42883: функция GetActiveUserPackagesForOpenBillingPeriod (отметка времени без часового пояса) не существует при попытке вызвать процедуру
Это код:
var date = DateTime.Now;
List<ActivePackageForOpenBillingPeriod> activeUserPackagesForOpenBillingPeriod = null;
using (var conn = new NpgsqlConnection ("Host=localhost;Port=xxx;Database=postgres;Username=postgres;Password=xxx;TrustServerCertificate=true;ApplicationName=xxx;"))
{
var s = "Select * FROM \"GetActiveUserPackagesForOpenBillingPeriod\"({0})";
activeUserPackagesForOpenBillingPeriod = context.ActivePackageForOpenBillingPeriods.FromSql (s, date).ToList ();
}
Хранимая процедура
create or replace function "GetActiveUserPackagesForOpenBillingPeriod"(somedate timestamp without time zone) returns TABLE("Amount" numeric, "Package" integer, "User" integer, "Account" integer, "AcceptanceActID" integer, "HasChangedPackage" boolean)
language plpgsql
as
$$
DECLARE
BEGIN
RETURN QUERY
SELECT
up."TotalAmount",
up."PackageID",
u."ID" AS "UserId",
a."ID" AS "AccountId",
th."AcceptanceActID",
CASE
WHEN count(DISTINCT tl."PackageID") IN (0,1) THEN false
ELSE true
END AS "HasChangedPackage"
FROM public."Accounts" as a
LEFT JOIN billing."TransactionHeaders" AS th ON th."AccountID" = a."ID"
INNER JOIN security."Users" AS u ON u."AccountID"= a."ID"
INNER JOIN billing."UserPackages" AS up ON up."UserID"=u."ID" AND COALESCE(th."Date", date) BETWEEN up."StartDate" AND COALESCE(up."EndDate", date)
LEFT JOIN billing."TransactionLines" AS tl ON th."Id" = tl."TransactionHeaderID"
WHERE th."AcceptanceActID" IS NULL AND a."StatusID"!=4 AND a."StatusID"!=3 AND up."StatusID"=1
GROUP BY a."ID", u."ID", up."PackageID",
up."TotalAmount",th."AcceptanceActID";
RETURN;
END;
$$;
alter function "GetActiveUserPackagesForOpenBillingPeriod"(timestamp)
owner
to postgres;
Класс
public class ActivePackageForOpenBillingPeriod {
public int Id { get; set; }
public int AccountID { get; set; }
[ForeignKey ("AccountID")]
public Account Account { get; set; }
public int UserID { get; set; }
[ForeignKey ("UserID")]
public User User { get; set; }
public int PackageID { get; set; }
[ForeignKey ("PackageID")]
public Package Package { get; set; }
public decimal TotalAmount { get; set; }
public bool HasChangedPackage { get; set; }
}