Exemple #1
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // if we don't have an ECM yet, go create one
            if (EntityContainerMapping == null)
            {
                var createECM = new CreateEntityContainerMappingCommand(AssociationSet.Artifact);
                CommandProcessor.InvokeSingleCommand(cpc, createECM);
                EntityContainerMapping = createECM.EntityContainerMapping;
            }

            Debug.Assert(EntityContainerMapping != null, "EntityContainerMapping should not be null");
            if (EntityContainerMapping == null)
            {
                throw new CannotLocateParentItemException();
            }

            // create the ETM
            var asm = new AssociationSetMapping(EntityContainerMapping, null);

            asm.Name.SetRefName(AssociationSet);
            asm.TypeName.SetRefName(Association);
            asm.StoreEntitySet.SetRefName(StorageEntitySet);
            EntityContainerMapping.AddAssociationSetMapping(asm);

            XmlModelHelper.NormalizeAndResolve(asm);

            Debug.Assert(asm.Name.Target != null, "Could not resolve association set reference");
            Debug.Assert(asm.TypeName.Target != null, "Could not resolve association type reference");
            Debug.Assert(asm.StoreEntitySet.Target != null, "Could not resolve table reference");

            var assoc = asm.TypeName.Target;

            Debug.Assert(assoc != null, "Could not resolve association reference");
            if (assoc != null)
            {
                InferReferentialConstraints.AddRule(cpc, assoc);
            }

            _created = asm;
        }