public int GetNumberOfShippedOrders(Guid customerAccountId) { const string sql = @"SELECT COUNT(OrderID) AS ShippedOrderCount FROM (SELECT DISTINCT a.OrderID FROM [Order] a (nolock) INNER JOIN dbo.OrderDetail b (nolock) ON a.OrderID = b.OrderID AND b.QtyShipped > 0 WHERE a.CustomerAccountId = @customerId ) AS T"; return _dbFactory.Exec(dbCmd => dbCmd.GetScalar<int>(sql, new { customerId = customerAccountId })); }
return
_dbFactory.Run(
command =>
command.QueryScalar<double>(
"EXEC [dbo].[GetPatrolAndServiceHoursForAgencies2] @StartDate, @EndDate, @HoursType",
new { StartDate = startDate, EndDate = endDate, HoursType = type }));
Query statements take in parameterized SQL using properties from the supplied anonymous type (if any)
var track3 = dbCmd.Query<Track>("select * from Track Where AlbumName = album and TrackNo = trackNo", new { album = "Throwing Copper", trackNo = 3 })
"EXEC [dbo].[GetPatrolAndServiceHoursForAgencies2] @StartDate = StartDate, @EndDate = EndDate, @HoursType = HoursType",
new { StartDate = startDate, EndDate = endDate, HoursType = type }));
public class HoursRequest {
public string StartDate { get; set; }
public string EndDate { get; set; }
public string HoursType { get; set; }
}
public double GetHoursFromType(string startDate, string endDate, string type)
{
return
_dbFactory.Run(
command =>
command.QueryScalar<double>(
"EXEC [dbo].[GetPatrolAndServiceHoursForAgencies2] @StartDate = StartDate, @EndDate = EndDate, @HoursType = HoursType",
new HoursRequest { StartDate = startDate, EndDate = endDate, HoursType = type }));
}
_dbFactory.Run(command => command.GetScalar<double>(string.Format("EXEC [stored_procedure_name] @Param1 = {0}, @Param2 = {1} ...", param1, param2)));