0

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

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

4 Comments

yes but I not want to pass ids for many records and it will check db everytime
I just want to pass whole row data to be used only in function
As I wrote above, PG supports the notion of "composite types", which can be used this way. These aren't supported in EF Core (github.com/npgsql/efcore.pg/issues/22).
I'll just say that it's somewhat questionable (especially in EF Core) to send row values to a function that doesn't actually access any table, but just does something with what you send it and returns the result... You may just as well perform the calculation client-side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.