internal static AssociationIdentity CreateAssociationIdentity(AssociationSetMapping asm)
        {
            var sSideEntitySet = asm.StoreEntitySet.Target as StorageEntitySet;
            if (null == sSideEntitySet)
            {
                // a null sSideEntitySet indicates an unresolved AssociationSetMapping
                // we treat this as equivalent to the AssociationSet being unmapped
                return null;
            }

            var assocId = new AssociationIdentityForAssociationSetMapping();
            assocId._assocTable = DatabaseObject.CreateFromEntitySet(sSideEntitySet);
            foreach (var endProp in asm.EndProperties())
            {
                var assocEndId = new AssociationEndIdentity(endProp);
                assocId.AddAssociationEndIdentity(assocEndId);
            }

            return assocId;
        }
        /// <summary>
        ///     Creates a new AssociationSetMapping in the existing EntityContainerMapping
        ///     based on another AssociationSetMapping (asmToClone) in a different artifact.
        ///     All the other parameters are presumed to already exist in the same artifact
        ///     as the EntityContainerMapping.
        /// </summary>
        private AssociationSetMapping CloneAssociationSetMapping(
            CommandProcessorContext cpc, AssociationSetMapping asmToClone,
            EntityContainerMapping existingEntityContainerMapping, AssociationSet existingAssociationSet,
            Association existingAssociation, StorageEntitySet existingStorageEntitySet,
            Dictionary<EntityType, EntityType> tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact)
        {
            var createASM = new CreateAssociationSetMappingCommand(
                existingEntityContainerMapping, existingAssociationSet, existingAssociation, existingStorageEntitySet);
            CommandProcessor.InvokeSingleCommand(cpc, createASM);
            var asmInExistingArtifact = createASM.AssociationSetMapping;

            if (null == asmInExistingArtifact)
            {
                throw new UpdateModelFromDatabaseException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.UpdateFromDatabaseCannotCreateAssociationSetMapping,
                        existingAssociationSet.ToPrettyString()));
            }

            // cannot just look for an AssociationSetEnd with the same Role name in
            // the existing artifact as the role may have changed when the Association was
            // copied into the existing artifact - but we do know the ends were created in 
            // the same order - so simply match them up
            var existingAssocSetEnds = existingAssociationSet.AssociationSetEnds().ToArray();
            if (2 != existingAssocSetEnds.Length)
            {
                throw new UpdateModelFromDatabaseException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.UpdateFromDatabaseAssociationSetMappingWrongNumberAssociationSetEnds,
                        existingAssociationSet.ToPrettyString(),
                        existingAssocSetEnds.Length));
            }

            var endsToClone = asmToClone.EndProperties().ToArray();
            if (2 != endsToClone.Length)
            {
                throw new UpdateModelFromDatabaseException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.UpdateFromDatabaseAssociationSetMappingWrongNumberAssociationSetEnds,
                        existingAssociationSet.ToPrettyString(),
                        existingAssocSetEnds.Length));
            }

            for (var i = 0; i < 2; i++)
            {
                var aseInExistingArtifact = existingAssocSetEnds[i];
                var endToClone = endsToClone[i];
                CloneEndProperty(
                    cpc, endToClone, asmInExistingArtifact, aseInExistingArtifact, tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact);
            }

            return asmInExistingArtifact;
        }