public void Update(PerformanceLog item)
        {
            try
            {
                ServiceContext.AttachTo(PerformanceLogContext.PerformanceLogTableName, item);
            }
            catch (InvalidOperationException e) // Context is already tracking the entity
            {
            }

            ServiceContext.UpdateObject(item);
            ServiceContext.SaveChanges();
        }
Example #2
0
        public void DeleteObject(string entityName, object entity)
        {
            Uri  editLink;
            var  entityType           = GetTypeDefinition(entityName);
            var  entityClrtype        = ResolveType(entityType.Name);
            bool hasIsDeletedProperty = HasField(entityClrtype, "IsDeleted");

            if (ServiceContext.TryGetUri(entity, out editLink))
            {
                if (hasIsDeletedProperty)
                {
                    ServiceContext.UpdateObject(entity);
                    SetFieldValue(entity, "IsDeleted", true);
                }
                else
                {
                    ServiceContext.DeleteObject(entity);
                }
                return;
            }
            var id = GetObjectId(entityName, entity);

            if (hasIsDeletedProperty)
            {
                var entityObject = GetOrNew(entityName, id, null);
                SetFieldValue(entityObject, "IsDeleted", true);
                ServiceContext.UpdateObject(entityObject);
            }
            else
            {
                var entityObject = Activator.CreateInstance(entityClrtype);
                SetEntityId(entityName, entityObject, id);
                var entitySetName = entityName.InflectTo().Pluralized;
                ServiceContext.AttachTo(entitySetName, entityObject);
                ServiceContext.DeleteObject(entityObject);
            }
        }
 public void Delete(PerformanceLog item)
 {
     ServiceContext.AttachTo(PerformanceLogContext.PerformanceLogTableName, item);
     ServiceContext.DeleteObject(item);
     ServiceContext.SaveChanges();
 }