Does Dapper do an auto-select of columns that match properties?
When using Dapper-dot-net, if your querying to a strongly typed results, and your SQL just has a:
select *
Will Dapper automappically only do a select on the columns that match the fields in your object? I think PetaPOCO does this but I ran into some problems开发者_开发百科 with dapper that I thought were attributed to this mismatch.
Example,
conn.Query<article>("select * from Article");
Will this work if the Article
table contains other columns that are extraneous to the article
object?
Yes it does - I tried this over the weekend, even with a query involved two tables joined by a FK constraint. I created two classes that represented only parts of those underlying tables, and those properties present will be filled just fine, anything that's not in the classes will be ignored. Works like a charm!
On the other hand: if you only need a few column - you should really specify those explicitly in your SQL query - as a general best practice! No point in selecting everything, if you need only a handful of columns....
精彩评论