Does Dapper automatically select columns matching properties?

When using Dapper-dot-net, if your query is for strongly typed results, and your SQL just has:

select * 

Will Dapper automatically only make choices in the columns corresponding to the fields of your object? I think PetaPOCO is doing this, but I ran into some dapper problems 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?

+4
source share
1 answer

Yes, the way it is - I tried it on the weekend, even if two tables connected by the FK constraint participated in the query. I created two classes that represent only parts of these base tables, and those properties that are present will be filled just fine, everything that is not in the classes will be ignored. It works like a charm!

On the other hand: if you need only one column, you should specify them explicitly in your SQL query - as a general best practice! It makes no sense to select everything if you need only a few columns ....

+5
source

All Articles