-
Notifications
You must be signed in to change notification settings - Fork 420
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
[Feature] Column Attribute #16
Comments
Anyone interested in this? |
I personally would definitely welcome this, similar to the table name attribute. Would be very helpful in legacy databases that have cryptic column names from being built in yesteryear and can't be altered. It would eliminate wrapping tables in views or hardcoded SQL in the data layer. |
@chrishylton that's exactly why I submitted the feature request, glad I'm not the only one working in a brownfield app :-) |
@mxmissile :-) yep, I frequently live in poo covered databases that have to be used in newer apps. Dapper and SimpleCRUD are lifesavers but I frequently get pushed back into Dapper proper due to this type of issue, or having to live with cryptic property names on my objects. The DBA in me says remove all security access to tables and push data through stored procedures or views with appropriate aliased column names. The developer in me has embraced Dapper and SimpleCRUD as my be-all-end-all data layer and screw the DBA in me. |
I added this. It was a bit harder than expected as it effected quite a bit. Get and GetList needed the select to specify column names rather than select *. When a column attribute is used it has to alias the column to the model name so model mapping happens. The where clause was a fun challenge too. You can use the anonymous object for the where clause based on the name in the model and SimpleCrud will figure out the database column name to query. Its on Nuget as a prerelease package until I can test it some more. Please let me know what you think. https://www.nuget.org/packages/Dapper.SimpleCRUD/1.7.0-prerelease |
eric, question on this. haven't had a chance to look into the code, so I suspect the answer is 'no', but can you somehow use the [Key] and [Column] attributes together. Looking to alias my db 'Id' column as something else in order to handle object/table inheritance and it doesn't seem to like the [Column] attribute if the [Key] attribute is there also. Thanks. Chris. btw, even w/ this issue (which i'm working around w/ a shallow copy of my object using reflection), this new [Column] capability is great. Thanks again for doing it ! ! ! |
Yes you can. There is a working example of this in the unit tests project. |
thanks eric, just now getting back to this. I'm either missing the unit test or looking in the wrong place. Looked in Dapper.SimpleCRUDTests (Tests.cs), but not seeing a combo of [Key] and [Column]. Tried it in my own code back before I posted the above question, and my Get< T > still errored out with the single key message. Don't have the example in front of me, but I can mock up an example of what I tried if you need it. No rush, I moved to a model of not even using an Id named column, my Key is Base._Id or Derived._DerivedId and mapped each w/ [Key] and this addressed my needs with my base/derived classes. |
Here is the model http://screencast.com/t/MoLwLxEw Is there something you need beyond that? |
um...nope...that'll do it. I promise, I pulled up Tests.cs today and searched for [Key and didn't run into what you have in your screencast. But obviously its there and its been there, found it tonight. I must be loosing it. Sorry. I must have had something else jacked up in my code, I'll try this again. Had both of those attributes on my class just like you have them in that test. Sorry for the run-around, I'll shut my pie-hole now. |
Its no problem. :) |
public class LineItem
{
[Column("order_id")]
public int OrderId {get;set;}
}
The text was updated successfully, but these errors were encountered: