The below code throws an error becuase the sql script requires storeId but it is not part of the DTO. The storeId is available from the calling function but i dont know how to pass it to dapper in a clean way.
Is there any dapper voodoo that will allow me to pass this value along with the list, without having to change the model or remap all the DTO properties to include the storeId?
public void UpsertOrders(int storeId, string location, IEnumerable<OrdersListing> listings, ILogger logger)
{
using (var connection = new SqlConnection(connectionString))
{
var sql = File.ReadAllText(@".\scripts\UpsertOrders.sql");
connection.Execute(sql, listings);
}
}
Untested, but perhaps:
connection.Execute(sql, listings.Select(x => {
var args = new DynamicParameters(x);
args.Add("storeId", storeId);
return args;
});