Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dapper maps when all columns listed, but not with * for select list #2023

Open
Crisfole opened this issue Jan 2, 2024 · 3 comments
Open

Comments

@Crisfole
Copy link

Crisfole commented Jan 2, 2024

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.

@Tim-Maes
Copy link

Tim-Maes commented Jan 4, 2024

Does the issue also occur when you use prototype to map the results?

As in

connection.QueryAsync(
        """
            SELECT *
            FROM TableExamples
            """,
        prototype: new {
            SecretId = default,
            Name = string.Empty,
            // other fields to map
        }
    )

I experience the same issue if I don't explicitly map the properties using prototype for the object

@Crisfole
Copy link
Author

Crisfole commented Jan 4, 2024

I'm mapping to existing Record types, not anonymous types, so I don't think that applies here.

@Crisfole
Copy link
Author

I added a (maybe) repro in #2029 I hope it helps. I can't get the tests running locally, but it demoes my theory. I'd love a hand getting the tests running so I can adequately express what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants