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?
To use the dynamic parameters you have to set each parameter in the stored procedure, so you will have to loop through the list and add each property to the coresponding parameter.
Dapper maps data to the first type in the same way as it does if only one generic parameter has been supplied to the QueryAsync<T> method. If is then told to map data to the Category type, and to assign the resulting object to the product's Category property.
splitOn: CustomerId will result in a null customer name. If you specify CustomerId,CustomerName as split points, dapper assumes you are trying to split up the result set into 3 objects. First starts at the beginning, second starts at CustomerId , third at CustomerName .
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....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With