private static async Task <ProductReadModel?> ReadProductAsync(SqlDataReader reader) { ProductReadModel?product = null; while (await reader.ReadAsync().ConfigureAwait(false)) //Todo CancellationTokens { var idx = 0; var id = reader.AsInt64(idx++); var brand = reader.AsStringOrNull(idx++); var color = reader.AsStringOrNull(idx++); var createTime = reader.AsDateTimeOrNull(idx++); var description = reader.AsStringOrNull(idx++); var discount = reader.AsFloatOrNull(idx++); var expiration = reader.AsDateTimeOrNull(idx++); var discountPrice = reader.AsDecimalOrNull(idx++); var isBaby = reader.AsBooleanOrNull(idx++); var gender = reader.AsEnumOrNull <Gender>(idx++); var isDeleted = reader.AsBooleanOrNull(idx++); var name = reader.AsStringOrNull(idx++); var price = reader.AsDecimal(idx++); var quantity = reader.AsByte(idx++); var productType = reader.AsString(idx++); var weight = reader.AsJsonOrNull <Weight>(idx++); var size = reader.AsStringOrNull(idx++); var url = reader.AsString(idx++); var isMainImage = reader.AsBoolean(idx++); var imgId = reader.AsInt64(idx++); var productId = reader.AsInt64(idx); if (product is null) { product = new ProductReadModel() { Id = id, Price = price, IsDeleted = isDeleted, Color = color, Brand = brand, ProductType = productType, Weight = weight, Name = name, Description = description, Gender = gender, ForBaby = isBaby, Size = size, Discount = discount, Quantity = quantity, CreateTime = createTime, DiscountPrice = discountPrice, Expiration = expiration, Images = new List <ProductReadModelImage>(6) { new () { Id = imgId, Url = url, MainImage = isMainImage, ProductId = productId, } } }; } else { product.Images.Add(new() { Id = imgId, Url = url, MainImage = isMainImage, ProductId = productId }); } } return(product); }