src/Misc/EFTools/EntityDesignModel/Commands/DeleteUnboundMappingsCommand.cs
/// <summary>
///     If this element has any children that have unresolved references
///     or has itself an unresolved reference then Delete the element
///     NB: Be warned this method is destructive. If you have unbound
///     elements for whatever reason then those elements will be removed.
/// </summary>
If this element has any children that have unresolved references
or has itself an unresolved reference then Delete the element
NB: Be warned this method is destructive. If you have unbound
elements for whatever reason then those elements will be removed.
If this element has any children that have unresolved references or has itself an unresolved reference then Delete the element NB : Be warned this method is destructive . If you have unbound elements for whatever reason then those elements will be removed .
private static void RecursiveDeleteUnboundElements(CommandProcessorContext cpc, EFElement efElement)
        {
            var mappingCondition = efElement as Condition;
            var queryView = efElement as QueryView;
            if (mappingCondition != null)
            {
                var children = efElement.Children.ToArray();
                var anyOneOfChildrenIsBound = 
                    children.OfType<ItemBinding>().Any(itemBinding => itemBinding.Resolved);
                if (!anyOneOfChildrenIsBound)
                {
                    DeleteEFElementCommand.DeleteInTransaction(cpc, efElement);
                }
                return;
            }
            else if (queryView != null)
            {
                return;
            }
            else
            {
                var children = new List<EFObject>(efElement.Children);
                var cp = efElement as ComplexProperty;
                if (cp != null)
                {
                    children.Remove(cp.TypeName);
                }
                var mf = efElement as ModificationFunction;
                if (mf != null)
                {
                    children.Remove(mf.RowsAffectedParameter);
                }
                foreach (var child in children)
                {
                    var efElementChild = child as EFElement;
                    var itemBindingChild = child as ItemBinding;
                    if (efElementChild != null)
                    {
                        RecursiveDeleteUnboundElements(cpc, efElementChild);
                    }
                    else if (itemBindingChild != null)
                    {
                        if (!itemBindingChild.Resolved)
                        {
                            DeleteEFElementCommand.DeleteInTransaction(cpc, efElement);
                            return;
                        }
                    }
                }
            }
        }
private static void RecursiveDeleteUnboundElements ( CommandProcessorContext cpc , EFElement efElement ) { var mappingCondition = efElement as Condition ; var queryView = efElement as QueryView ; if ( mappingCondition != null ) { var children = efElement . Children . ToArray ( ) ; var anyOneOfChildrenIsBound = children . OfType < ItemBinding > ( ) . Any ( itemBinding => itemBinding . Resolved ) ; if ( ! anyOneOfChildrenIsBound ) { DeleteEFElementCommand . DeleteInTransaction ( cpc , efElement ) ; } return ; } else if ( queryView != null ) { return ; } else { var children = new List < EFObject > ( efElement . Children ) ; var cp = efElement as ComplexProperty ; if ( cp != null ) { children . Remove ( cp . TypeName ) ; } var mf = efElement as ModificationFunction ; if ( mf != null ) { children . Remove ( mf . RowsAffectedParameter ) ; } foreach ( var child in children ) { var efElementChild = child as EFElement ; var itemBindingChild = child as ItemBinding ; if ( efElementChild != null ) { RecursiveDeleteUnboundElements ( cpc , efElementChild ) ; } else if ( itemBindingChild != null ) { if ( ! itemBindingChild . Resolved ) { DeleteEFElementCommand . DeleteInTransaction ( cpc , efElement ) ; return ; } } } } }
If this element has any children that have unresolved references
or has itself an unresolved reference then Delete the element
NB: Be warned this method is destructive.
If this element has any children that have unresolved references or has itself an unresolved reference then Delete the element NB : Be warned this method is destructive .
// A Mapping Condition is special because it will  // only ever have 1 bound child out of 2 // QueryView elements have a TypeName attribute, but it is optional and // so the QueryView should not be deleted even if the TypeName attribute // is not in a Resolved state // cannot use IEnumerable directly as we are potentially // deleting from the returned collection // remove any children which are optional (and hence not being resolved does not require a delete) // TypeName binding in ComplexProperty is optional and can be unresolved, so remove it from the check list // loop over children and recursively delete
cpc
CommandProcessorContext
efElement
EFElement