Dapper maps when all columns listed, but not with `*` for select list
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I really don't know why this happens, but Dapper is having trouble mapping columns with underscore matching enabled, but only when I use SELECT * or SELECT alias.* in my SQL.
The following class:
public record TableExample(
Guid ExampleUuid,
int SecretId,
string Name,
DateTime ValidStart,
DateTime? ValidEnd
);
Does not work for this sql:
select tbl.* from TableExamples
But does work for this sql:
select example_uuid, secret_id, name, valid_start, valid_end from TableExample
The error is complaining (barely paraphrased because my console scrolled past my history limit):
an empty constructor or a constructor matching (System.Guid example_uuid, System.Int32 secret_id, System.String name, System.DateTime valid_start, System.DateTime valid_end) is required for Parking.API.Integrations.OdeVehicle materialization.
I can't really figure out how to debug this. I only managed to figure out the workaround by manually mapping in the query with Pascale case columns, and then deleting half at a time in search for the failure to map. The DateTime? doesn't seem to be it because it works.
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
Start with the supplied TableExample record and compare the two SQL forms under underscore matching: SELECT tbl.* and the explicit column list. Reproduce the constructor-materialization error, then trace the mapping behavior for wildcard versus explicit columns; done means both queries map the record successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100