src/Misc/EFTools/EntityDesignModel/Commands/CreateInheritanceCommand.cs
/// <summary>
///     We override this to register an integrity check, and to deal with association set ends that reference
///     the existing entity set (which is going to be deleted)
/// </summary>
We override this to register an integrity check, and to deal with association set ends that reference
the existing entity set (which is going to be deleted)
We override this to register an integrity check and to deal with association set ends that reference the existing entity set ( which is going to be deleted )
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            base.PreInvoke(cpc);
            if (EntityToBeDerived == null
                || EntityToBeDerived.BaseType.Target != null)
            {
                throw new InvalidOperationException();
            }
            EnforceEntitySetMappingRules.AddRule(cpc, BaseType.EntitySet);
            var associationsToUpdate = new HashSet<Association>();
            if (EntityToBeDerived.EntitySet != null)
            {
                var associationSetEndsToUpdate = EntityToBeDerived.EntitySet.GetAntiDependenciesOfType<AssociationSetEnd>();
                foreach (var setEnd in associationSetEndsToUpdate)
                {
                    setEnd.EntitySet.SetRefName(BaseType.EntitySet);
                    XmlModelHelper.NormalizeAndResolve(setEnd);
                    var aSet = setEnd.Parent as AssociationSet;
                    if (aSet != null)
                    {
                        if (aSet.Association.Target != null)
                        {
                            associationsToUpdate.Add(aSet.Association.Target);
                        }
                    }
                }
            }
            foreach (var association in associationsToUpdate)
            {
                if (association != null
                    && association.AssociationSet != null
                    && association.AssociationSet.AssociationSetMapping != null
                    && association.AssociationSet.AssociationSetMapping.XObject != null)
                {
                    var storeEntitySet = association.AssociationSet.AssociationSetMapping.StoreEntitySet.Target;
                    DeleteEFElementCommand.DeleteInTransaction(cpc, association.AssociationSet.AssociationSetMapping);
                    if (storeEntitySet != null
                        && storeEntitySet.EntityType.Target != null)
                    {
                        var set = storeEntitySet.EntityType.Target as StorageEntityType;
                        Debug.Assert(set != null, "EntityType is not StorageEntityType");
                        CreateAssociationSetMappingCommand.CreateAssociationSetMappingAndIntellimatch(cpc, association, set);
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] protected override void PreInvoke ( CommandProcessorContext cpc ) { base . PreInvoke ( cpc ) ; if ( EntityToBeDerived == null || EntityToBeDerived . BaseType . Target != null ) { throw new InvalidOperationException ( ) ; } EnforceEntitySetMappingRules . AddRule ( cpc , BaseType . EntitySet ) ; var associationsToUpdate = new HashSet < Association > ( ) ; if ( EntityToBeDerived . EntitySet != null ) { var associationSetEndsToUpdate = EntityToBeDerived . EntitySet . GetAntiDependenciesOfType < AssociationSetEnd > ( ) ; foreach ( var setEnd in associationSetEndsToUpdate ) { setEnd . EntitySet . SetRefName ( BaseType . EntitySet ) ; XmlModelHelper . NormalizeAndResolve ( setEnd ) ; var aSet = setEnd . Parent as AssociationSet ; if ( aSet != null ) { if ( aSet . Association . Target != null ) { associationsToUpdate . Add ( aSet . Association . Target ) ; } } } } foreach ( var association in associationsToUpdate ) { if ( association != null && association . AssociationSet != null && association . AssociationSet . AssociationSetMapping != null && association . AssociationSet . AssociationSetMapping . XObject != null ) { var storeEntitySet = association . AssociationSet . AssociationSetMapping . StoreEntitySet . Target ; DeleteEFElementCommand . DeleteInTransaction ( cpc , association . AssociationSet . AssociationSetMapping ) ; if ( storeEntitySet != null && storeEntitySet . EntityType . Target != null ) { var set = storeEntitySet . EntityType . Target as StorageEntityType ; Debug . Assert ( set != null , " " ) ; CreateAssociationSetMappingCommand . CreateAssociationSetMappingAndIntellimatch ( cpc , association , set ) ; } } } }
We override this to register an integrity check, and to deal with association set ends that reference
the existing entity set (which is going to be deleted)
We override this to register an integrity check and to deal with association set ends that reference the existing entity set ( which is going to be deleted )
// you cannot use this command with a type that already has a base class; throwing here // because its not a good idea to throw an exception in a c'tor // see if this type is used by association ends; since we are creating an inheritance // we need to change any AssociationSetEnd references from the current EntitySet to the // new baseType's EntitySet (the derived type's EntitySet will be deleted) // try to recreate the AssociationSetMapping if one exists // store off the entity set for later // delete it // create a new one (if we can)
cpc
CommandProcessorContext