How to pass array of records in parameters with npgsql
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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