diff --git a/NEW/src/JdeScoping.DataAccess/Queries/LotFinderQueries.Lookups.cs b/NEW/src/JdeScoping.DataAccess/Queries/LotFinderQueries.Lookups.cs index 2162120..5986551 100644 --- a/NEW/src/JdeScoping.DataAccess/Queries/LotFinderQueries.Lookups.cs +++ b/NEW/src/JdeScoping.DataAccess/Queries/LotFinderQueries.Lookups.cs @@ -20,7 +20,7 @@ public static partial class LotFinderQueries ORDER BY i.ItemNumber"; /// - /// Looks up items by exact item numbers using table-valued parameter. + /// Looks up items by exact item numbers using STRING_SPLIT. /// public const string SqlLookupItems = @" SELECT i.ShortItemNumber, @@ -28,16 +28,16 @@ public static partial class LotFinderQueries i.Description, i.LastUpdateDT FROM dbo.Item AS i - INNER JOIN @itemNumbers AS i2 ON (i.ItemNumber = i2.ItemNumber) + WHERE i.ItemNumber IN (SELECT LTRIM(RTRIM(value)) FROM STRING_SPLIT(@itemNumbers, ',')) ORDER BY i.ItemNumber"; /// - /// Looks up work orders by work order numbers using table-valued parameter. + /// Looks up work orders by work order numbers using STRING_SPLIT. /// public const string SqlLookupWorkorders = @" SELECT * FROM dbo.WorkOrder AS wo - INNER JOIN @workOrderNumbers wo2 ON (wo.WorkOrderNumber = wo2.WorkOrderNumber)"; + WHERE wo.WorkOrderNumber IN (SELECT CAST(LTRIM(RTRIM(value)) AS BIGINT) FROM STRING_SPLIT(@workOrderNumbers, ','))"; /// /// Searches work centers by code or description. @@ -53,14 +53,14 @@ public static partial class LotFinderQueries ORDER BY wc.Code"; /// - /// Looks up work centers by codes using table-valued parameter. + /// Looks up work centers by codes using STRING_SPLIT. /// public const string SqlLookupWorkCenters = @" SELECT wc.Code, wc.Description, wc.LastUpdateDT FROM dbo.WorkCenter AS wc - INNER JOIN @workCenterCodes wc2 ON (wc.Code = wc2.Code) + WHERE wc.Code IN (SELECT LTRIM(RTRIM(value)) FROM STRING_SPLIT(@workCenterCodes, ',')) ORDER BY wc.Code"; /// @@ -77,14 +77,14 @@ public static partial class LotFinderQueries ORDER BY pc.Code"; /// - /// Looks up profit centers by codes using table-valued parameter. + /// Looks up profit centers by codes using STRING_SPLIT. /// public const string SqlLookupProfitCenters = @" SELECT pc.Code, pc.Description, pc.LastUpdateDT FROM dbo.ProfitCenter AS pc - INNER JOIN @profitCenterCodes AS pc2 ON (pc.Code = pc2.Code) + WHERE pc.Code IN (SELECT LTRIM(RTRIM(value)) FROM STRING_SPLIT(@profitCenterCodes, ',')) ORDER BY pc.Code"; /// @@ -103,7 +103,7 @@ public static partial class LotFinderQueries ORDER BY u.UserID, u.FullName"; /// - /// Looks up users by user IDs or address numbers using table-valued parameter. + /// Looks up users by user IDs or address numbers using STRING_SPLIT. /// public const string SqlLookupUsers = @" SELECT u.AddressNumber, @@ -111,11 +111,12 @@ public static partial class LotFinderQueries u.FullName, u.LastUpdateDT FROM dbo.JdeUser AS u - INNER JOIN @userIDs u2 ON (u.UserID = u2.UserName OR CAST(u.AddressNumber AS VARCHAR(20)) = u2.UserName) + WHERE u.UserID IN (SELECT LTRIM(RTRIM(value)) FROM STRING_SPLIT(@userIds, ',')) + OR CAST(u.AddressNumber AS VARCHAR(20)) IN (SELECT LTRIM(RTRIM(value)) FROM STRING_SPLIT(@userIds, ',')) ORDER BY u.UserID"; /// - /// Looks up lots by lot number and item number using table-valued parameter. + /// Looks up lots by lot number and item number using OPENJSON. /// public const string SqlLookupLots = @" SELECT DISTINCT @@ -126,6 +127,9 @@ public static partial class LotFinderQueries l.SupplierCode, l.LastUpdateDT FROM dbo.Lot AS l - INNER JOIN @lotNumbers ln ON (l.LotNumber = ln.ComponentLotNumber AND + INNER JOIN OPENJSON(@lotsJson) WITH ( + LotNumber VARCHAR(30) '$.LotNumber', + ItemNumber VARCHAR(128) '$.ItemNumber' + ) ln ON (l.LotNumber = ln.LotNumber AND ((l.ItemNumber IS NULL AND ln.ItemNumber IS NULL) OR l.ItemNumber = ln.ItemNumber))"; } diff --git a/NEW/src/JdeScoping.DataAccess/Repositories/LotFinderRepository.Lookups.cs b/NEW/src/JdeScoping.DataAccess/Repositories/LotFinderRepository.Lookups.cs index 80a9451..45f7b8b 100644 --- a/NEW/src/JdeScoping.DataAccess/Repositories/LotFinderRepository.Lookups.cs +++ b/NEW/src/JdeScoping.DataAccess/Repositories/LotFinderRepository.Lookups.cs @@ -1,4 +1,3 @@ -using System.Data; using Dapper; using JdeScoping.Core.Models; using JdeScoping.Core.Models.Inventory; @@ -44,17 +43,12 @@ public partial class LotFinderRepository const string operation = nameof(LookupItemsAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("ItemNumber", typeof(string)); - foreach (var itemNumber in itemNumbers) - { - dataTable.Rows.Add(itemNumber); - } + var itemNumbersCsv = string.Join(",", itemNumbers); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupItems, - new { itemNumbers = dataTable.AsTableValuedParameter("ItemNumberFilterParameter") }, + new { itemNumbers = itemNumbersCsv }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); } @@ -75,17 +69,12 @@ public partial class LotFinderRepository const string operation = nameof(LookupWorkordersAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("WorkOrderNumber", typeof(long)); - foreach (var workOrderNumber in workorderNumbers) - { - dataTable.Rows.Add(workOrderNumber); - } + var workOrderNumbersCsv = string.Join(",", workorderNumbers); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupWorkorders, - new { workOrderNumbers = dataTable.AsTableValuedParameter("WorkOrderFilterParameter") }, + new { workOrderNumbers = workOrderNumbersCsv }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); } @@ -130,17 +119,12 @@ public partial class LotFinderRepository const string operation = nameof(LookupWorkCentersAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("Code", typeof(string)); - foreach (var code in codes) - { - dataTable.Rows.Add(code); - } + var workCenterCodesCsv = string.Join(",", codes); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupWorkCenters, - new { workCenterCodes = dataTable.AsTableValuedParameter("WorkCenterFilterParameter") }, + new { workCenterCodes = workCenterCodesCsv }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); } @@ -185,17 +169,12 @@ public partial class LotFinderRepository const string operation = nameof(LookupProfitCentersAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("Code", typeof(string)); - foreach (var code in codes) - { - dataTable.Rows.Add(code); - } + var profitCenterCodesCsv = string.Join(",", codes); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupProfitCenters, - new { profitCenterCodes = dataTable.AsTableValuedParameter("ProfitCenterFilterParameter") }, + new { profitCenterCodes = profitCenterCodesCsv }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); } @@ -240,17 +219,12 @@ public partial class LotFinderRepository const string operation = nameof(LookupUsersAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("UserName", typeof(string)); - foreach (var userId in userIds) - { - dataTable.Rows.Add(userId); - } + var userIdsCsv = string.Join(",", userIds); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupUsers, - new { userIDs = dataTable.AsTableValuedParameter("OperatorFilterParameter") }, + new { userIds = userIdsCsv }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); } @@ -271,18 +245,13 @@ public partial class LotFinderRepository const string operation = nameof(LookupLotsAsync); try { - var dataTable = new DataTable(); - dataTable.Columns.Add("ComponentLotNumber", typeof(string)); - dataTable.Columns.Add("ItemNumber", typeof(string)); - foreach (var lot in lots) - { - dataTable.Rows.Add(lot.LotNumber, lot.ItemNumber); - } + var lotsJson = System.Text.Json.JsonSerializer.Serialize( + lots.Select(l => new { l.LotNumber, l.ItemNumber })); await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(ct); var result = await connection.QueryAsync( LotFinderQueries.SqlLookupLots, - new { lotNumbers = dataTable.AsTableValuedParameter("ComponentLotFilterParameter") }, + new { lotsJson }, commandTimeout: _options.Value.DefaultTimeoutSeconds); return result.ToList(); }