Ali Hussain
Ali Hussain

Reputation: 896

How to pass a row as a parameter to a Postgres function using .net core DBFunction

Passing pgsql table object as parameter using c# .net core?

HI in pgsql we can pass table row as parameter , I want to know how we can use it in .net core?

like below function takes some parameters and give its functionality

   -CREATE OR REPLACE FUNCTION public."GetUserName"(u "User_", pmed "Pharmacy", puser "Pharmacy", m "Medication")
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
    return (
        case when u."Id" > 0 then
            (
                u."FirstName" || ' ' ||coalesce(u."LastName", '')
                || (
                    case when u."Pharmacy_Id" > 0 then
                            (case when puser."PharmacyId" > 0 then ' (' || puser."PharmacyName" || ') ' else '' end)
                    else '' end
                )
            )
        when coalesce (u."Id" , 0) = 0 then pmed."PharmacyName" else '' end
    );
END
$function$
;

I want to call this function using .net core ef core without dynamic queries using DbFunctions appraoch

Upvotes: 0

Views: 657

Answers (1)

Shay Rojansky
Shay Rojansky

Reputation: 16692

Rather than trying to pass an entire row as a parameter to a function - which usually wouldn't be very efficient - try passing the primary key of that row instead. Your function can then perform any queries or updates on that row as usual.

In general, in relational databases a row doesn't exist as an entity you pass around or manipulate as such (although PostgreSQL does have 1st-class support for composite types, which also back tables).

Upvotes: 1

Related Questions