internal static void AddRule(CommandProcessorContext cpc, EntitySet element)
 {
     if (element != null)
     {
         foreach (var esm in element.GetAntiDependenciesOfType<EntitySetMapping>())
         {
             AddRule(cpc, esm);
         }
     }
 }
 internal void AddEntitySet(EntitySet set)
 {
     _entitySets.Add(set);
 }
 public ExplorerEntitySet(EditingContext context, EntitySet entitySet, ExplorerEFElement parent)
     : base(context, entitySet, parent)
 {
     // do nothing
 }
        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;
        }
 private ExplorerEntitySet AddEntitySet(EntitySet entitySet)
 {
     var explorerEntitySet =
         ModelToExplorerModelXRef.GetNew(_context, entitySet, this, typeof(ExplorerEntitySet)) as ExplorerEntitySet;
     _entitySets.Insert(explorerEntitySet);
     return explorerEntitySet;
 }