예제 #1
0
        /// <summary>
        /// Method is done as a cleanup, when a resource is deleted, this method will remove the deleted object from an entityInstance reference property
        /// </summary>
        /// <param name="targetResource">Resource to look for in the currentEntityInstance</param>
        /// <param name="navigationPropertyInfo">NavigationProperty to look in on the currentEntityInstance</param>
        /// <param name="currentEntityInstance">currentEntityInstance that may contain the targetResource</param>
        private void SetEntityReferenceToNullOnTargetResourceMatch(object targetResource, NavigationPropertyInfo navigationPropertyInfo, object currentEntityInstance)
        {
            object childReferenceObject = navigationPropertyInfo.PropertyInfo.GetValue(currentEntityInstance, null);

            if (childReferenceObject == targetResource)
            {
                this.pendingChanges.Add(() => navigationPropertyInfo.PropertyInfo.SetValue(currentEntityInstance, null, null));
            }
        }
예제 #2
0
        /// <summary>
        /// Method is done as a cleanup, when a resource is deleted, this method will remove the deleted object from an entityInstance collection property
        /// </summary>
        /// <param name="targetResource">Resource to look for in the currentEntityInstance</param>
        /// <param name="navigationPropertyInfo">NavigationProperty to look in on the currentEntityInstance</param>
        /// <param name="currentEntityInstance">currentEntityInstance that may contain the targetResource</param>
        private void RemoveResourceFromCollectionOnTargetResourceMatch(object targetResource, NavigationPropertyInfo navigationPropertyInfo, object currentEntityInstance)
        {
            IEnumerable childCollectionObject = navigationPropertyInfo.PropertyInfo.GetValue(currentEntityInstance, null) as IEnumerable;

            if (childCollectionObject.Cast <object>().Any(o => o == targetResource))
            {
                MethodInfo removeMethod = navigationPropertyInfo.PropertyInfo.PropertyType.GetMethod("Remove");
                this.pendingChanges.Add(() => removeMethod.Invoke(childCollectionObject, new object[] { targetResource }));
            }
        }