Пример #1
0
        public async Task DeleteShipment(int shipmentID)
        {
            // Trigger manual cascade delete
            // Shipment has MANY orders PK = ShipmentID
            // Orders has MANY items PK = OrderID FK = ShipmentID
            // Items has ONE Order PK = ItemID FK = OrderID
            var shipmentDelete = _dbContext.Shipments.SingleOrDefault(s => s.ShipmentID == shipmentID);

            var orderRows = _dbContext.Shipments.Where(s => s.ShipmentID == shipmentID)
                            .Include(s => s.Orders).SelectMany(s => s.Orders);

            var items = orderRows.Include(o => o.Items).SelectMany(o => o.Items);

            _dbContext.Items.RemoveRange(items);
            _dbContext.Orders.RemoveRange(orderRows);
            _dbContext.Shipments.Remove(shipmentDelete);

            await _dbContext.SaveChangesAsync();
        }
 public async Task <int> Save()
 {
     return(await _shipmentContext.SaveChangesAsync());
 }