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

[Feature] Column Attribute #16

Closed
mxmissile opened this issue Jul 10, 2014 · 11 comments
Closed

[Feature] Column Attribute #16

mxmissile opened this issue Jul 10, 2014 · 11 comments

Comments

@mxmissile
Copy link

public class LineItem
{
[Column("order_id")]
public int OrderId {get;set;}
}

@ericdc1
Copy link
Owner

ericdc1 commented Dec 30, 2014

Anyone interested in this?

@chrishylton
Copy link

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.

@mxmissile
Copy link
Author

@chrishylton that's exactly why I submitted the feature request, glad I'm not the only one working in a brownfield app :-)

@chrishylton
Copy link

@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.

@ericdc1
Copy link
Owner

ericdc1 commented Jan 6, 2015

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

@ericdc1 ericdc1 closed this as completed Jan 6, 2015
@chrishylton
Copy link

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 ! ! !

@ericdc1
Copy link
Owner

ericdc1 commented Feb 19, 2015

Yes you can. There is a working example of this in the unit tests project.

@chrishylton
Copy link

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.

@ericdc1
Copy link
Owner

ericdc1 commented Feb 25, 2015

Here is the model http://screencast.com/t/MoLwLxEw
And here are a few of the tests http://screencast.com/t/LTwLL2jyQ6MC

Is there something you need beyond that?

@chrishylton
Copy link

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.

@ericdc1
Copy link
Owner

ericdc1 commented Feb 25, 2015

Its no problem. :)

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

3 participants