0

I wrote a function in my postgresql database that returns an array I would like to retrieve its values ​​in my application which is aspnet core c #.

here is the function signature

CREATE OR REPLACE FUNCTION Search (source integer, destination integer)
RETURNS table (
Idvoyage integer,
Name1 text,
SourId integer,
DestId integer)
AS $ trip $
2

1 Answer 1

1

After several searches I finally found how to use my function on the same site of stackoverflow but I lost the link but I put the code for people that could help here "searchforserchticketall" is my function in my database and command.Parameters.Add (new Npgsql.NpgsqlParameter ("source", NpgsqlTypes.NpgsqlDbType.Integer) {Value = source}); command.Parameters.Add (new Npgsql.NpgsqlParameter ("companyid", NpgsqlTypes.NpgsqlDbType.Integer) my two parameters next command.ExecuteReader () to execute the function

  using (var command = _context.Database.GetDbConnection().CreateCommand())
            {
                var function = "Transport.";
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "searchforserchticketall";
                command.Parameters.Add(new Npgsql.NpgsqlParameter("source", NpgsqlTypes.NpgsqlDbType.Integer)
                { Value = source });
                command.Parameters.Add(new Npgsql.NpgsqlParameter("compagnieid", NpgsqlTypes.NpgsqlDbType.Integer)
                { Value = compagnieid });
                if (command.Connection.State == ConnectionState.Closed)
                    command.Connection.Open();
                var res = command.ExecuteReader();

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

Comments

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.