internal CreateEntitySetMappingCommand(EntityContainerMapping entityContainerMapping, ConceptualEntitySet entitySet)
        {
            Debug.Assert(entitySet != null, "entitySet should not be null");
            Debug.Assert(entitySet.Artifact != null, "entitySet's artifact should not be null");

            CommandValidation.ValidateConceptualEntitySet(entitySet);

            _entityContainerMapping = entityContainerMapping;
            _entitySet = entitySet;
        }
        internal CreateEntitySetMappingCommand(EntityContainerMapping entityContainerMapping, ConceptualEntitySet entitySet)
        {
            Debug.Assert(entitySet != null, "entitySet should not be null");
            Debug.Assert(entitySet.Artifact != null, "entitySet's artifact should not be null");

            CommandValidation.ValidateConceptualEntitySet(entitySet);

            _entityContainerMapping = entityContainerMapping;
            _entitySet = entitySet;
        }
 internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == EntitySet.ElementName)
     {
         EntitySet es = new ConceptualEntitySet(this, elem);
         AddEntitySet(es);
         es.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == FunctionImport.ElementName)
     {
         var fi = new FunctionImport(this, elem);
         _functionImports.Add(fi);
         fi.Parse(unprocessedElements);
     }
     else
     {
         return base.ParseSingleElement(unprocessedElements, elem);
     }
     return true;
 }
Exemplo n.º 4
0
 internal static void ValidateConceptualEntitySet(ConceptualEntitySet conceptualEntitySet)
 {
     ValidateEFElement(conceptualEntitySet);
     Debug.Assert(conceptualEntitySet.EntityType.Target != null, "The passed in C-Side EntitySet has unknown entity binding");
 }
Exemplo n.º 5
0
        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;
        }
        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;
        }
Exemplo n.º 7
0
 internal static void ValidateConceptualEntitySet(ConceptualEntitySet conceptualEntitySet)
 {
     ValidateEFElement(conceptualEntitySet);
     Debug.Assert(conceptualEntitySet.EntityType.Target != null, "The passed in C-Side EntitySet has unknown entity binding");
 }
        /// <summary>
        ///     Creates a new EntitySetMapping in the existing EntityContainerMapping
        ///     based on another EntitySetMapping (esmToClone) in a different artifact.
        ///     Uses the FindMatchingEntityTypeInExistingArtifact() to match EntityTypes
        ///     within the EntitySetMapping.
        /// </summary>
        private EntitySetMapping CloneEntitySetMapping(
            CommandProcessorContext cpc, EntitySetMapping esmToClone,
            EntityContainerMapping existingEntityContainerMapping, ConceptualEntitySet existingEntitySet,
            Dictionary<EntityType, EntityType> tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact)
        {
            var createESM = new CreateEntitySetMappingCommand(existingEntityContainerMapping, existingEntitySet);
            CommandProcessor.InvokeSingleCommand(cpc, createESM);
            var esm = createESM.EntitySetMapping;

            foreach (var etmToBeCloned in esmToClone.EntityTypeMappings())
            {
                var bindings = etmToBeCloned.TypeName.Bindings;
                if (bindings.Count != 1)
                {
                    Debug.Fail(
                        "EntityTypeMapping to be cloned " + etmToBeCloned.ToPrettyString() +
                        " has bindings count = " + bindings.Count + ". We only support 1 binding.");
                }
                else
                {
                    var b = bindings.First();
                    var etToBeCloned = b.Target as ConceptualEntityType;
                    Debug.Assert(etToBeCloned != null, "EntityType target of binding is not ConceptualEntityType");
                    var etInExistingArtifact =
                        FindMatchingConceptualEntityTypeInExistingArtifact(
                            etToBeCloned,
                            tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact);
                    if (null != etInExistingArtifact)
                    {
                        CreateEntityTypeMappingCommand.CloneEntityTypeMapping(
                            cpc,
                            etmToBeCloned,
                            esm,
                            etInExistingArtifact,
                            etmToBeCloned.Kind);
                    }
                    else
                    {
                        throw new UpdateModelFromDatabaseException(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                Resources.UpdateFromDatabaseEntitySetMappingCannotFindEntityType,
                                etToBeCloned.ToPrettyString()));
                    }
                }
            }

            return esm;
        }