private void SynchronizeItems(IntraWarehouseOrder order, tblRincon oldOrder)
        {
            var currentDetails = order.PickedInventory.Items.Select(i => new RinconDetail(i, oldOrder, OldContextHelper)).ToList();

            SynchronizeItems(currentDetails.Select(d => d.Detail), oldOrder.tblRinconDetails, OldContext.tblRinconDetails, DetailMatchPredicates,
                             n => n.RDetailID = OldContext.tblRinconDetails.GetNextUnique(oldOrder.RinconID, d => d.RDetailID),
                             (o, n) =>
            {
                o.EmployeeID = n.EmployeeID;
                o.Lot        = n.Lot;
                o.PkgID      = n.PkgID;
                o.TrtmtID    = n.TrtmtID;
                o.Quantity   = n.Quantity;
                o.CurrLocID  = n.CurrLocID;
                o.DestLocID  = n.DestLocID;
            });

            SynchronizeItems(currentDetails.SelectMany(d => d.ToOutgoingRecords()), oldOrder.tblOutgoings, OldContext.tblOutgoings, OutgoingMatchPredicates,
                             n => n.ID = OldContext.tblOutgoings.GetNextUnique(o => o.ID),
                             (o, n) =>
            {
                o.EntryDate       = n.EntryDate;
                o.Lot             = n.Lot;
                o.PkgID           = n.PkgID;
                o.Quantity        = n.Quantity;
                o.NetWgt          = n.NetWgt;
                o.TtlWgt          = n.TtlWgt;
                o.LocID           = n.LocID;
                o.TrtmtID         = n.TrtmtID;
                o.EmployeeID      = n.EmployeeID;
                o.CustProductCode = n.CustProductCode;
            });
        }
        private tblRincon Synchronize(IntraWarehouseOrder order, out bool createdNew)
        {
            createdNew = false;
            tblRincon oldOrder;

            if (order.RinconID == null)
            {
                createdNew = true;
                oldOrder   = new tblRincon
                {
                    RinconID = OldContext.tblRincons.GetNextUnique(DateTime.UtcNow.ConvertUTCToLocal(), r => r.RinconID)
                };
                OldContext.tblRincons.AddObject(oldOrder);
                order.RinconID = oldOrder.RinconID;
            }
            else
            {
                var oldOrderSelect = OldContext.tblRincons
                                     .Select(r => new
                {
                    rincon  = r,
                    details = r.tblRinconDetails
                })
                                     .FirstOrDefault(r => r.rincon.RinconID == order.RinconID.Value);
                if (oldOrderSelect == null)
                {
                    throw new Exception(string.Format("tblRincon[{0}] not found in old context.", order.RinconID));
                }
                oldOrder = oldOrderSelect.rincon;
            }

            oldOrder.MoveDate   = order.MovementDate.Date;
            oldOrder.SheetNum   = order.TrackingSheetNumber;
            oldOrder.PrepBy     = order.OperatorName;
            oldOrder.Updated    = order.TimeStamp.ConvertUTCToLocal();
            oldOrder.EmployeeID = order.EmployeeId;

            if (createdNew)
            {
                SynchronizeItems(order, oldOrder);
            }

            return(oldOrder);
        }