public ExplorerEntityContainer( EditingContext context, BaseEntityContainer entityContainer, ExplorerEFElement parent) : base(context, entityContainer, parent) { _entitySetsGhostNode = new ExplorerEntityContainerEntitySets( Resources.EntitySetsGhostNodeName, context, this); _assocSetsGhostNode = new ExplorerEntityContainerAssociationSets( Resources.AssociationSetsGhostNodeName, context, this); }
protected override void InvokeInternal(CommandProcessorContext cpc) { Debug.Assert(Association != null, "InvokeInternal is called when Association is null."); if (Association == null) { throw new InvalidOperationException("InvokeInternal is called when Association is null"); } var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the entity container we want to add it to BaseEntityContainer entityContainer = null; switch (CommandModelSpace) { case ModelSpace.Conceptual: entityContainer = artifact.ConceptualModel().FirstEntityContainer; break; case ModelSpace.Storage: entityContainer = artifact.StorageModel().FirstEntityContainer; break; } Debug.Assert(entityContainer != null, "No entity container"); // check for uniqueness string msg = null; if (ModelHelper.IsUniqueName(typeof(AssociationSet), entityContainer, Name, false, out msg) == false) { throw new InvalidOperationException(msg); } // create the new item in our model var associationSet = new AssociationSet(entityContainer, null); associationSet.LocalName.Value = Name; entityContainer.AddAssociationSet(associationSet); // set the association binding: needs to happen before the ends are resolved if (Association != null) { associationSet.Association.SetRefName(Association); } // TODO: what should we create if these bindings are unknown? var end1 = Association.AssociationEnds()[0]; var end2 = Association.AssociationEnds()[1]; if (end1 != null && end1.Type.Status == BindingStatus.Known && end2 != null && end2.Type.Status == BindingStatus.Known) { var setEnd1 = new AssociationSetEnd(associationSet, null); setEnd1.Role.SetRefName(end1); setEnd1.EntitySet.SetRefName(end1.Type.Target.EntitySet); associationSet.AddAssociationSetEnd(setEnd1); var setEnd2 = new AssociationSetEnd(associationSet, null); setEnd2.Role.SetRefName(end2); setEnd2.EntitySet.SetRefName(end2.Type.Target.EntitySet); associationSet.AddAssociationSetEnd(setEnd2); } XmlModelHelper.NormalizeAndResolve(associationSet); _createdAssociationSet = associationSet; }
protected override void InvokeInternal(CommandProcessorContext cpc) { Debug.Assert(EntityType != null, "InvokeInternal is called when EntityType is null"); if (EntityType == null) { throw new InvalidOperationException("InvokeInternal is called when EntityType is null"); } var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // locate the entity container we want to add it to BaseEntityContainer entityContainer = null; EntitySet entitySet = null; switch (ModelSpaceValue) { case ModelSpace.Conceptual: Debug.Assert(artifact.ConceptualModel() != null, "artifact.ConceptualModel() should not be null"); entityContainer = artifact.ConceptualModel().FirstEntityContainer; break; case ModelSpace.Storage: Debug.Assert(artifact.StorageModel() != null, "artifact.StorageModel() should not be null"); entityContainer = artifact.StorageModel().FirstEntityContainer; break; default: Debug.Fail("Unknown model space"); break; } Debug.Assert(entityContainer != null, "entityContainer should not be null"); if (entityContainer == null) { throw new CannotLocateParentItemException(); } // check for uniqueness of the name within the chosen EC if (UniquifyName) { Name = ModelHelper.GetUniqueName(typeof(EntitySet), entityContainer, Name); } else { string msg = null; if (ModelHelper.IsUniqueName(typeof(EntitySet), entityContainer, Name, false, out msg) == false) { throw new CommandValidationFailedException(msg); } } // create the entity set; don't need to assert on enum since that has happened above if (ModelSpaceValue == ModelSpace.Conceptual) { entitySet = new ConceptualEntitySet(entityContainer, null); } else { entitySet = new StorageEntitySet(entityContainer, null); // DefiningQuery creation if (DefiningQueryContent != null) { var definingQuery = new DefiningQuery(entitySet, null); definingQuery.XElement.SetValue(DefiningQueryContent); ((StorageEntitySet)entitySet).DefiningQuery = definingQuery; } } Debug.Assert(entitySet != null, "entitySet should not be null"); if (entitySet == null) { throw new ItemCreationFailureException(); } // set name and add to the parent entitySet.LocalName.Value = Name; entityContainer.AddEntitySet(entitySet); // set the entity type binding if (EntityType != null) { entitySet.EntityType.SetRefName(EntityType); } XmlModelHelper.NormalizeAndResolve(entitySet); EntitySet = entitySet; }