public List <AbstractItemData> GetByIds(int siteId, bool isArchive, IEnumerable <int> itemIds, IDbTransaction transaction = null) { _logger.LogDebug($"getByIds. siteId: {siteId}, isArchive: {isArchive}, itemIds: {SerializeData(itemIds)}"); if (itemIds == null || !itemIds.Any()) { throw new ArgumentNullException("itemIds"); } if (itemIds.Any(x => x <= 0)) { throw new ArgumentException("itemId <= 0"); } var idList = SqlQuerySyntaxHelper.IdList(_uow.DatabaseType, "@ItemIds", "itemIds"); var query = GetCmdGetAbstractItemByIds(siteId, isArchive, idList); List <AbstractItemData> result; if (_uow.DatabaseType == DatabaseType.SqlServer) { result = _uow.Connection.Query <AbstractItemData>(query, new { ItemIds = SqlQuerySyntaxHelper.IdsToDataTable(itemIds).AsTableValuedParameter("Ids") }, transaction) .ToList(); } else { result = _uow.Connection.Query <AbstractItemData>(query, new { ItemIds = itemIds }, transaction).ToList(); } _logger.LogDebug($"getByIds. count: {result.Count}, result: {SerializeData(result)}"); return(result); }
public List <AbstractItemData> GetItems(int siteId, bool isArchive, IEnumerable <int> parentIds, bool useRegion, IDbTransaction transaction = null) { _logger.LogDebug( $"getItems. siteId: {siteId}, isArchive: {isArchive}, useRegion: {useRegion}, parentIds: {SerializeData(parentIds)}"); const int maxParentIdsPerRequest = 500; List <AbstractItemData> items; string query; if (parentIds == null || !parentIds.Any()) { query = GetAbstractItemsQuery(siteId, isArchive, "IS NULL"); items = _uow.Connection.Query <AbstractItemData>(query, transaction).ToList(); if (useRegion) { AddRegionInfo(siteId, isArchive, items); } _logger.LogDebug($"getItems. count: {items.Count}"); return(items); } if (parentIds.Count() > maxParentIdsPerRequest) { items = new List <AbstractItemData>(); for (var i = 0; i < (float)parentIds.Count() / maxParentIdsPerRequest; i++) { int[] r = parentIds.Skip(i * maxParentIdsPerRequest).Take(maxParentIdsPerRequest).ToArray(); items.AddRange(GetItems(siteId, isArchive, r, useRegion)); } _logger.LogDebug($"getItems. count: {items.Count}"); return(items); } var idList = SqlQuerySyntaxHelper.IdList(_uow.DatabaseType, "@ParentIds", "parentIds"); query = GetAbstractItemsQuery(siteId, isArchive, $"IN (SELECT Id FROM {idList})"); if (_uow.DatabaseType == DatabaseType.SqlServer) { items = _uow.Connection.Query <AbstractItemData>(query, new { ParentIds = SqlQuerySyntaxHelper.IdsToDataTable(parentIds).AsTableValuedParameter("Ids") }, transaction) .ToList(); } else { items = _uow.Connection.Query <AbstractItemData>(query, new { ParentIds = parentIds }, transaction).ToList(); } if (useRegion) { AddRegionInfo(siteId, isArchive, items); } return(items); }