-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 Contrib - Column mapping #623
Conversation
At a cursory glance, this also appears to be a breaking change for anyone with non-aliased columns, inherited classes, etc. The |
The goal overall is to be able to override the default Column Name To Property Name mapping. So, I believe it would be necessary to generate a column list for However, I don't understand how this breaks anything. The default behaviour here is to generate a column names, equal to the POCO's property names. Is this not already the assumption with |
@mjashanks There's a matching problem in either direction here. Let me see if I can clear it up a bit: We have a choice at the first level: do we enumerate all of the columns for the In general, Dapper is a "get everything, map what's there", because that's the only safe scenario to do such. Contrib could behave differently in generation forcing mapping of all columns with attributes that that's hard for 2 reasons: a) it's a breaking change, and b) you (currently) have no way to control classes that aren't yours, e.g. from a shared library or something else. |
@NickCraver - appreciate you taking the time to explain. I have modified this so that it uses |
I have made a PR with the same functionality, only a different implementation. I believe it's a bit more compatible. #653 |
@mjashanks I'm consolidating all of the discussion here into #722, would you please weigh in and help us design this feature to work for as many cases as we reasonably can? |
This allows us to apply Property -> Column mapping in a pluggable way.
I originally made this pull request, which was too opinionated: #376
That previous PR was closed, and batched into: #385
I believe that issue 385 is not the correct place for this, as it is talking specifically about making the mapper more pluggable (i.e. Mapping the data from SqlDataReader to a POCO) - which would only cover SELECTs.
My PR, is more about the generated SQL that is executed, thus covers INSERT, UPDATE, DELETE & SELECT - i.e. the responsibility of Dapper.Contrib
I have implemented in a similar way to
TableNameMapper
.. where the user must override the following delegates:GetAllColumns
- returns all mappings for a typeGetPersistentColumns
- returns writeable (i.e. Insert & update) mappings for a typeGetKeyColumns
- returns key mappings for a typeThis would be a breaking change for anybody who has implemented their own ISqlAdapter, but that is all
I have only tested this for SQL Server