From dfcba9101c23a0d674a187fe190eb4667315d133 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 2 Sep 2022 11:07:12 -0700 Subject: [PATCH 1/2] Fix local build errors --- src/SqlAsyncCollector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SqlAsyncCollector.cs b/src/SqlAsyncCollector.cs index bdb6ee0d8..a8a517468 100644 --- a/src/SqlAsyncCollector.cs +++ b/src/SqlAsyncCollector.cs @@ -351,7 +351,7 @@ public class TableInformation { private const string ISO_8061_DATETIME_FORMAT = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff"; - public IEnumerable PrimaryKeys { get; } + public IEnumerable PrimaryKeys { get; } /// /// All of the columns, along with their data types, for SQL to use to turn JSON into a table @@ -385,7 +385,7 @@ public class TableInformation /// public JsonSerializerSettings JsonSerializerSettings { get; } - public TableInformation(IEnumerable primaryKeys, IDictionary columns, StringComparer comparer, string query, bool hasIdentityColumnPrimaryKeys) + public TableInformation(IEnumerable primaryKeys, IDictionary columns, StringComparer comparer, string query, bool hasIdentityColumnPrimaryKeys) { this.PrimaryKeys = primaryKeys; this.Columns = columns; @@ -624,7 +624,7 @@ public static async Task RetrieveTableInformationAsync(SqlConn // Match SQL Primary Key column names to POCO field/property objects. Ensure none are missing. StringComparison comparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; - IEnumerable primaryKeyFields = typeof(T).GetMembers().Where(f => primaryKeys.Any(k => string.Equals(k.Name, f.Name, comparison))); + IEnumerable primaryKeyFields = typeof(T).GetProperties().Where(f => primaryKeys.Any(k => string.Equals(k.Name, f.Name, comparison))); IEnumerable primaryKeysFromObject = columnNames.Where(f => primaryKeys.Any(k => string.Equals(k.Name, f, comparison))); IEnumerable missingPrimaryKeysFromItem = primaryKeys .Where(k => !primaryKeysFromObject.Contains(k.Name, comparer)); From eedbf4903ce47b2bc8db5554c3981773bbe82a29 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 2 Sep 2022 11:12:35 -0700 Subject: [PATCH 2/2] Update comments --- src/SqlAsyncCollector.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SqlAsyncCollector.cs b/src/SqlAsyncCollector.cs index a8a517468..34c732da3 100644 --- a/src/SqlAsyncCollector.cs +++ b/src/SqlAsyncCollector.cs @@ -305,7 +305,7 @@ private static void GenerateDataQueryForMerge(TableInformation table, IEnumerabl { // SQL Server allows 900 bytes per primary key, so use that as a baseline var combinedPrimaryKey = new StringBuilder(900 * table.PrimaryKeys.Count()); - // Look up primary key of T. Because we're going in the same order of fields every time, + // Look up primary key of T. Because we're going in the same order of properties every time, // we can assume that if two rows with the same primary key are in the list, they will collide foreach (PropertyInfo primaryKey in table.PrimaryKeys) { @@ -622,9 +622,9 @@ public static async Task RetrieveTableInformationAsync(SqlConn throw ex; } - // Match SQL Primary Key column names to POCO field/property objects. Ensure none are missing. + // Match SQL Primary Key column names to POCO property objects. Ensure none are missing. StringComparison comparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; - IEnumerable primaryKeyFields = typeof(T).GetProperties().Where(f => primaryKeys.Any(k => string.Equals(k.Name, f.Name, comparison))); + IEnumerable primaryKeyProperties = typeof(T).GetProperties().Where(f => primaryKeys.Any(k => string.Equals(k.Name, f.Name, comparison))); IEnumerable primaryKeysFromObject = columnNames.Where(f => primaryKeys.Any(k => string.Equals(k.Name, f, comparison))); IEnumerable missingPrimaryKeysFromItem = primaryKeys .Where(k => !primaryKeysFromObject.Contains(k.Name, comparer)); @@ -654,8 +654,8 @@ public static async Task RetrieveTableInformationAsync(SqlConn sqlConnProps.Add(TelemetryPropertyName.QueryType, usingInsertQuery ? "insert" : "merge"); sqlConnProps.Add(TelemetryPropertyName.HasIdentityColumn, hasIdentityColumnPrimaryKeys.ToString()); TelemetryInstance.TrackDuration(TelemetryEventName.GetTableInfoEnd, tableInfoSw.ElapsedMilliseconds, sqlConnProps, durations); - logger.LogDebugWithThreadId($"END RetrieveTableInformationAsync Duration={tableInfoSw.ElapsedMilliseconds}ms DB and Table: {sqlConnection.Database}.{fullName}. Primary keys: [{string.Join(",", primaryKeyFields.Select(pk => pk.Name))}]. SQL Column and Definitions: [{string.Join(",", columnDefinitionsFromSQL)}]"); - return new TableInformation(primaryKeyFields, columnDefinitionsFromSQL, comparer, query, hasIdentityColumnPrimaryKeys); + logger.LogDebugWithThreadId($"END RetrieveTableInformationAsync Duration={tableInfoSw.ElapsedMilliseconds}ms DB and Table: {sqlConnection.Database}.{fullName}. Primary keys: [{string.Join(",", primaryKeyProperties.Select(pk => pk.Name))}]. SQL Column and Definitions: [{string.Join(",", columnDefinitionsFromSQL)}]"); + return new TableInformation(primaryKeyProperties, columnDefinitionsFromSQL, comparer, query, hasIdentityColumnPrimaryKeys); } }