public int Insert(IDbConnection connection, IDbTransaction transaction, int?commandTimeout, string tableName, string columnList, string parameterList, IEnumerable <PropertyInfo> keyProperties, object entityToInsert) { var cmd = $"insert into {tableName} ({columnList}) values ({parameterList});select SCOPE_IDENTITY() id"; var multi = connection.QueryMultiple(cmd, entityToInsert, transaction, commandTimeout); var first = multi.Read().FirstOrDefault(); if (first == null || first.id == null) { return(0); } var id = (int)first.id; var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray(); if (!propertyInfos.Any()) { return(id); } var idProperty = propertyInfos.First(); idProperty.SetValue(entityToInsert, Convert.ChangeType(id, idProperty.PropertyType), null); return(id); }
public int Insert(IDbConnection connection, IDbTransaction transaction, int?commandTimeout, string tableName, string columnList, string parameterList, IEnumerable <PropertyInfo> keyProperties, object entityToInsert) { var cmd = $"INSERT INTO {tableName} ({columnList}) VALUES ({parameterList}); SELECT last_insert_rowid() id"; var multi = connection.QueryMultiple(cmd, entityToInsert, transaction, commandTimeout); var id = (int)multi.Read().First().id; var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray(); if (!propertyInfos.Any()) { return(id); } var idProperty = propertyInfos.First(); idProperty.SetValue(entityToInsert, Convert.ChangeType(id, idProperty.PropertyType), null); return(id); }
public static List<AvailabilityGroupReplicaInfo> PopulateFromConnection(DbConnection conn, SQLNode node) { List<AvailabilityGroupReplicaInfo> groups; List<DatabaseReplicaState> databases; var sql = node.GetFetchSQL<AvailabilityGroupReplicaInfo>() + "\n\n" + node.GetFetchSQL<DatabaseReplicaState>(); using (var multi = conn.QueryMultiple(sql)) { groups = multi.Read<AvailabilityGroupReplicaInfo>().ToList(); databases = multi.Read<DatabaseReplicaState>().ToList(); } Func<string, string, PerfCounterRecord> getCounter = (cn, n) => node.GetPerfCounter("Availability Replica", cn, n); groups.ForEach(r => { r.Databases = databases.Where(gdb => r.GroupId == gdb.GroupId && r.ReplicaId == gdb.ReplicaId).ToList(); var instanceName = r.AvailabilityGroupName + ":" + r.ReplicaServerName; var sc = getCounter("Bytes Sent to Transport/sec", instanceName); if (sc != null) { r.BytesSentPerSecond = sc.CalculatedValue; r.BytesSentTotal = sc.CurrentValue; } var rc = getCounter("Bytes Received from Replica/sec", instanceName); if (rc != null) { r.BytesReceivedPerSecond = rc.CalculatedValue; r.BytesReceivedTotal = rc.CurrentValue; } }); return groups; }
/// <summary> /// Load individual MiniProfiler /// </summary> /// <param name="connection">The connection.</param> /// <param name="keyParameter">The id Parameter.</param> /// <returns>Related MiniProfiler object</returns> private MiniProfiler LoadProfilerRecord(DbConnection connection, object keyParameter) { MiniProfiler profiler; using (var multi = connection.QueryMultiple(SqlStatements, keyParameter)) { profiler = multi.Read<MiniProfiler>().SingleOrDefault(); var timings = multi.Read<Timing>().ToList(); var clientTimings = multi.Read<ClientTimings.ClientTiming>().ToList(); if (profiler != null && profiler.RootTimingId.HasValue && timings.Any()) { var rootTiming = timings.SingleOrDefault(x => x.Id == profiler.RootTimingId.Value); if (rootTiming != null) { profiler.Root = rootTiming; timings.ForEach(x => x.Profiler = profiler); timings.Remove(rootTiming); var timingsLookupByParent = timings.ToLookup(x => x.ParentTimingId, x => x); PopulateChildTimings(rootTiming, timingsLookupByParent); } if (clientTimings.Any() || profiler.ClientTimingsRedirectCount.HasValue) { profiler.ClientTimings = new ClientTimings { RedirectCount = profiler.ClientTimingsRedirectCount ?? 0, Timings = clientTimings }; } } } return profiler; }