public virtual Task<IEnumerable<InvocationState>> GetByInstance(string instanceName, DateTime? start, DateTime? end, int? limit)
{
var limitStr = "";
if (limit != null)
{
limitStr = "TOP (" + limit.Value.ToString() + ") ";
}
return ConnectAndQuery(@"
SELECT " + limitStr + @"*
FROM [work].Invocations
WHERE [JobInstanceName] = @instanceName
AND (@start IS NULL OR [UpdatedAt] >= @start)
AND (@end IS NULL OR [UpdatedAt] <= @end)
ORDER BY UpdatedAt DESC", new { instanceName, start, end });
}