public void RevertChanges(bool isSaveOnClientRecord)
        {
            _objectContext.DetectChanges();

            IEnumerable<object> ModifiedandDeletedcollection = _objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Modified | EntityState.Deleted).Select(x => x.Entity).ToList();
            _objectContext.Refresh(RefreshMode.StoreWins, ModifiedandDeletedcollection);


            IEnumerable<object> AddedCollection = _objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(x => x.Entity).ToList();

           // AddedCollection.ForEach(addedEntity => _objectContext.Detach(addedEntity));
   
            foreach(var addedEntity in AddedCollection)
            {
               if(addedEntity.GetType().Name == "Corresponcence")
               {
                   Corresponcence entity = (Corresponcence)addedEntity;
                   if(entity.OwnerID == Guid.Empty)
                   {
                     _objectContext.Detach(addedEntity);
                   }
                   else if (!isSaveOnClientRecord)
                   {
                       _objectContext.Detach(addedEntity);
                   }
               }
            }
        }
示例#2
0
        public void DetachGolfEvent(Guid golfEventId)
        {
            var AddedGolfEvent = _objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Where(x => x.EntitySet.Name == _objectContext.EventGolfs.EntitySet.Name && ((EventGolf)x.Entity).ID == golfEventId).Select(x => (EventGolf)x.Entity).FirstOrDefault();

            if (AddedGolfEvent != null)
            {
                _objectContext.Detach(AddedGolfEvent);
            }
        }
示例#3
0
        public void RevertAllChanges()
        {
            _objectContext.DetectChanges();

            IEnumerable <object> modifiedandDeletedcollection = _objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Modified | EntityState.Deleted).Select(x => x.Entity).ToList();

            _objectContext.Refresh(RefreshMode.StoreWins, modifiedandDeletedcollection);

            IEnumerable <object> addedCollection = _objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(x => x.Entity).ToList();

            addedCollection.ForEach(addedEntity => _objectContext.Detach(addedEntity));
        }