DapperLib / DapperLib/Dapper

How to pass array of records in parameters with npgsql

Open
#2,046 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

How to pass array of records postgres type as a parameter from c#?

I have tried to send it the same way it is received from query result - as double array of objects, but npgsql complains about it:

            var result = await dbContext.Database.GetDbConnection().QueryAsync<Person>(
                new CommandDefinition(
                    commandText: sql,
                    parameters: new
                    {
                        People = ids
                            .Select(t => new object[]
                            {
                                t.FirstName,
                                t.LastName
                            })
                            .ToArray()
                    },
                    cancellationToken: cancellationToken));

The CLR type System.Object isn't natively supported by Npgsql or your PostgreSQL. To use it with a PostgreSQL composite you need
to specify DataTypeName or to map it, please refer to the documentation.

I guess I need to use DynamicParameters object and specify type name manually, but it accepts enum instead of string and in enum there is no such value like object or record.

I need it for query like this one:

SELECT * FROM peopletable
WHERE ROW(firstname, lastname) = ANY(@people)

Can someone guide me how to do it?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names the QueryAsync call, CommandDefinition, DynamicParameters, and the SQL using @people, but no repository files or tests. Start by tracing Dapper's parameter binding and comparing it with Npgsql's PostgreSQL composite-array requirements. Done would be a reproducible resolution for passing the peopletable record array to the shown query.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql, sql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.