private async Task CreateRandomQuery() { StringBuilder sql = new StringBuilder("SELECT inc, UserId, GroupId, Status, Name, Age FROM Table1 WHERE 1=1 "); object parameterValues = AddWhere(sql); var profiler = new CustomDbProfiler(); using (var connection = ProfiledDbConnectionFactory.New(new SqlServerDbConnectionFactory(_connectionString), profiler)) { connection.Open(); try { Type[] types = new [] { typeof(IncClass), typeof(UserClass), typeof(GroupClass), typeof(StatusClass), typeof(NameClass) }; string splitOn = "UserId, GroupId, Status, Name"; var result = await connection.QueryAsync(sql.ToString(), map : (objects) => { var restaurantOrder = (IncClass)objects[0]; restaurantOrder.User = (UserClass)objects[1]; restaurantOrder.Group = (GroupClass)objects[2]; restaurantOrder.StatusObj = (StatusClass)objects[3]; restaurantOrder.NameObj = (NameClass)objects[4]; return(restaurantOrder); }, types : types, splitOn : splitOn, param : parameterValues).ConfigureAwait(false); } catch (SqlException e) { e.Data["profile-query-after-dapper"] = profiler.GetCommands(); e.AppendExceptionData(sql.ToString(), parameterValues); throw; } } }
private T[] GetValues <T>(string field) { var profiler = new CustomDbProfiler(); using (var connection = ProfiledDbConnectionFactory.New(new SqlServerDbConnectionFactory(_connectionString), profiler)) { var result = connection.Query <T>($"SELECT DISTINCT {field} FROM Table1"); return(result.ToArray()); } }
public static string GetCommands(this CustomDbProfiler dbProfiler) { return dbProfiler.ProfilerContext.GetCommands(); }