Exemplo n.º 1
0
        public void DeleteFromRepository(PlantCode itemCode)
        {
            if (_repositoryContext.GetEntityDescriptor(itemCode) != null)
            {//if it exists in the db delete it from the db
                PlantEntities context = new PlantEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                PlantCode deletedPlantCode = (from q in context.PlantCodes
                                              where q.PlantCodeID == itemCode.PlantCodeID
                                              select q).FirstOrDefault();
                if (deletedPlantCode != null)
                {
                    context.DeleteObject(deletedPlantCode);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetPlantCodeEntityState(itemCode) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(itemCode);
                }
            }
        }