コード例 #1
0
        public async Task CreateOrderProductsAsync(int orderId, IEnumerable <int> productIds)
        {
            IEnumerable <OrderProduct> GetOrderProducts()
            {
                foreach (var productId in productIds)
                {
                    yield return(new OrderProduct
                    {
                        OrderId = orderId,
                        ProductId = productId,
                    });
                }
            }

            await _orderProductRepository.CreateRangeAsync(GetOrderProducts());

            await _orderProductRepository.SaveChangesAsync();
        }