/// <summary>
        ///     Creates an EntityTypeMapping for the passed in type and kind.   If an ETM of the kind doesn't exist,
        ///     then it creates it.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="kind"></param>
        internal CreateEntityTypeMappingCommand(ConceptualEntityType entityType, EntityTypeMappingKind kind)
        {
            CommandValidation.ValidateConceptualEntityType(entityType);

            _entityType = entityType;
            _kind = kind;
        }
        private void ProcessEntityTypeMapping(EntityInfo info, EntityTypeMappingKind kind)
        {
            var etm = ModelHelper.FindEntityTypeMapping(_cpc, info.EntityType, kind, false);

            if (info.UsesEntityTypeMappingKind(kind))
            {
                // find or create the entity type mapping
                if (etm == null)
                {
                    var createETM = new CreateEntityTypeMappingCommand(
                        _entitySetMapping,
                        info.EntityType,
                        kind);
                    CommandProcessor.InvokeSingleCommand(_cpc, createETM);
                    etm = createETM.EntityTypeMapping;
                }
                Debug.Assert(etm != null, "Could not locate or create the required EntityTypeMapping");

                ProcessMappingFragments(info, etm);
            }
            else
            {
                // don't need it, remove it if we have one
                if (etm != null)
                {
                    AddToDeleteList(etm);
                }
            }
        }
        /// <summary>
        ///     Creates an EntityTypeMapping for the passed in type and kind.   If an ETM of the kind doesn't exist,
        ///     then it creates it.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="kind"></param>
        internal CreateEntityTypeMappingCommand(ConceptualEntityType entityType, EntityTypeMappingKind kind)
        {
            CommandValidation.ValidateConceptualEntityType(entityType);

            _entityType = entityType;
            _kind       = kind;
        }
        /// <summary>
        ///     Creates a MappingFragment for the passed in StorageEntitySet in the passed in ETM.
        /// </summary>
        /// <param name="entityTypeMapping">This must a valid EntityTypeMapping.</param>
        /// <param name="entitySet">This must be a valid StorageEntitySet.</param>
        internal CreateMappingFragmentCommand(EntityTypeMapping entityTypeMapping, StorageEntitySet storageEntitySet)
        {
            CommandValidation.ValidateEntityTypeMapping(entityTypeMapping);
            CommandValidation.ValidateStorageEntitySet(storageEntitySet);

            ConceptualEntityType   = entityTypeMapping.FirstBoundConceptualEntityType;
            _entityTypeMappingKind = entityTypeMapping.Kind;
            _entityTypeMapping     = entityTypeMapping;
            StorageEntitySet       = storageEntitySet;
        }
        /// <summary>
        ///     Creates a MappingFragment for the passed in StorageEntitySet in the passed in ETM.
        /// </summary>
        /// <param name="entityTypeMapping">This must a valid EntityTypeMapping.</param>
        /// <param name="entitySet">This must be a valid StorageEntitySet.</param>
        internal CreateMappingFragmentCommand(EntityTypeMapping entityTypeMapping, StorageEntitySet storageEntitySet)
        {
            CommandValidation.ValidateEntityTypeMapping(entityTypeMapping);
            CommandValidation.ValidateStorageEntitySet(storageEntitySet);

            ConceptualEntityType = entityTypeMapping.FirstBoundConceptualEntityType;
            _entityTypeMappingKind = entityTypeMapping.Kind;
            _entityTypeMapping = entityTypeMapping;
            StorageEntitySet = storageEntitySet;
        }
        /// <summary>
        ///     Create MappingFragment for the passed in ConceptualEntityType and StoreEntityType, and inside the
        ///     ETM based on the passed in kind.
        /// </summary>
        /// <param name="conceptualEntityType">This must be a valid EntityType from the C-Model.</param>
        /// <param name="storeEntityType">This must be a valid EntityType from the S-Model.</param>
        /// <param name="kind">Specify whether this should be put in an IsTypeOf or Default ETM</param>
        internal CreateMappingFragmentCommand(EntityType conceptualEntityType, EntityType storeEntityType, EntityTypeMappingKind kind)
        {
            CommandValidation.ValidateStorageEntityType(storeEntityType);
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);

            ConceptualEntityType = conceptualEntityType;
            _entityTypeMappingKind = kind;
            _entityTypeMapping = null;
            StorageEntitySet = storeEntityType.EntitySet as StorageEntitySet;

            CommandValidation.ValidateStorageEntitySet(StorageEntitySet);
        }
        /// <summary>
        ///     Create MappingFragment for the passed in ConceptualEntityType and StoreEntityType, and inside the
        ///     ETM based on the passed in kind.
        /// </summary>
        /// <param name="conceptualEntityType">This must be a valid EntityType from the C-Model.</param>
        /// <param name="storeEntityType">This must be a valid EntityType from the S-Model.</param>
        /// <param name="kind">Specify whether this should be put in an IsTypeOf or Default ETM</param>
        internal CreateMappingFragmentCommand(EntityType conceptualEntityType, EntityType storeEntityType, EntityTypeMappingKind kind)
        {
            CommandValidation.ValidateStorageEntityType(storeEntityType);
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);

            ConceptualEntityType   = conceptualEntityType;
            _entityTypeMappingKind = kind;
            _entityTypeMapping     = null;
            StorageEntitySet       = storeEntityType.EntitySet as StorageEntitySet;

            CommandValidation.ValidateStorageEntitySet(StorageEntitySet);
        }
            internal bool UsesEntityTypeMappingKind(EntityTypeMappingKind kind)
            {
                // for non-abstract types, evaluate what is needed
                foreach (var pair in Tables)
                {
                    if (pair.Value.UsesEntityTypeMappingKind(kind))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            private static string DumpEntityTypeMappingKindToString(EntityTypeMappingKind kind)
            {
                if (kind == EntityTypeMappingKind.Default)
                {
                    return("Default");
                }
                if (kind == EntityTypeMappingKind.IsTypeOf)
                {
                    return("IsTypeOf");
                }

                return("Derive");
            }
Esempio n. 10
0
        protected override void PreParse()
        {
            Debug.Assert(State != EFElementState.Parsed, "this object should not already be in the parsed state");

            ClearEFObject(_entityTypes);
            _entityTypes = null;

            // once we have children that we can parse, set this to Derive and figure out the kind dynamically
            _kind = EntityTypeMappingKind.Derive;

            ClearEFObjectCollection(_fragments);

            ClearEFObject(_modificationFunctionMapping);
            _modificationFunctionMapping = null;

            base.PreParse();
        }
        /// <summary>
        ///     Creates a new EntityTypeMapping in the existing EntitySetMapping
        ///     based on another EntityTypeMapping (etmToClone) in a different artifact.
        ///     All the other parameters are presumed to already exist in the same artifact
        ///     as the EntitySetMapping.
        /// </summary>
        internal static EntityTypeMapping CloneEntityTypeMapping(
            CommandProcessorContext cpc,
            EntityTypeMapping etmToClone, EntitySetMapping existingEntitySetMapping,
            ConceptualEntityType existingEntityType, EntityTypeMappingKind kind)
        {
            var createETM = new CreateEntityTypeMappingCommand(existingEntitySetMapping, existingEntityType, kind);
            var cp        = new CommandProcessor(cpc, createETM);

            cp.Invoke();

            var etm = createETM.EntityTypeMapping;

            foreach (var mappingFragment in etmToClone.MappingFragments())
            {
                var sesToClone = mappingFragment.StoreEntitySet.Target as StorageEntitySet;
                var ses        = existingEntitySetMapping.EntityContainerMapping.Artifact.
                                 StorageModel().FirstEntityContainer.GetFirstNamedChildByLocalName(sesToClone.LocalName.Value)
                                 as StorageEntitySet;
                CreateMappingFragmentCommand.CloneMappingFragment(cpc, mappingFragment, etm, ses);
            }

            return(etm);
        }
        /// <summary>
        ///     Creates a new EntityTypeMapping in the existing EntitySetMapping
        ///     based on another EntityTypeMapping (etmToClone) in a different artifact.
        ///     All the other parameters are presumed to already exist in the same artifact
        ///     as the EntitySetMapping.
        /// </summary>
        internal static EntityTypeMapping CloneEntityTypeMapping(
            CommandProcessorContext cpc,
            EntityTypeMapping etmToClone, EntitySetMapping existingEntitySetMapping,
            ConceptualEntityType existingEntityType, EntityTypeMappingKind kind)
        {
            var createETM = new CreateEntityTypeMappingCommand(existingEntitySetMapping, existingEntityType, kind);
            var cp = new CommandProcessor(cpc, createETM);
            cp.Invoke();

            var etm = createETM.EntityTypeMapping;

            foreach (var mappingFragment in etmToClone.MappingFragments())
            {
                var sesToClone = mappingFragment.StoreEntitySet.Target as StorageEntitySet;
                var ses = existingEntitySetMapping.EntityContainerMapping.Artifact.
                              StorageModel().FirstEntityContainer.GetFirstNamedChildByLocalName(sesToClone.LocalName.Value)
                          as StorageEntitySet;
                CreateMappingFragmentCommand.CloneMappingFragment(cpc, mappingFragment, etm, ses);
            }

            return etm;
        }
            internal bool UsesEntityTypeMappingKind(EntityTypeMappingKind kind)
            {
                // for non-abstract types, evaluate what is needed
                foreach (var pair in Tables)
                {
                    if (pair.Value.UsesEntityTypeMappingKind(kind))
                    {
                        return true;
                    }
                }

                return false;
            }
        private static string DumpEntityTypeMappingKindToString(EntityTypeMappingKind kind)
        {
            if (kind == EntityTypeMappingKind.Default) return "Default";
            if (kind == EntityTypeMappingKind.IsTypeOf) return "IsTypeOf";

            return "Derive";
        }
        private void ProcessEntityTypeMapping(EntityInfo info, EntityTypeMappingKind kind)
        {
            var etm = ModelHelper.FindEntityTypeMapping(_cpc, info.EntityType, kind, false);

            if (info.UsesEntityTypeMappingKind(kind))
            {
                // find or create the entity type mapping
                if (etm == null)
                {
                    var createETM = new CreateEntityTypeMappingCommand(
                        _entitySetMapping,
                        info.EntityType,
                        kind);
                    CommandProcessor.InvokeSingleCommand(_cpc, createETM);
                    etm = createETM.EntityTypeMapping;
                }
                Debug.Assert(etm != null, "Could not locate or create the required EntityTypeMapping");

                ProcessMappingFragments(info, etm);
            }
            else
            {
                // don't need it, remove it if we have one
                if (etm != null)
                {
                    AddToDeleteList(etm);
                }
            }
        }
 internal bool UsesEntityTypeMappingKind(EntityTypeMappingKind kind)
 {
     return (EntityTypeMappingKind == kind);
 }
        protected override void PreParse()
        {
            Debug.Assert(State != EFElementState.Parsed, "this object should not already be in the parsed state");

            ClearEFObject(_entityTypes);
            _entityTypes = null;

            // once we have children that we can parse, set this to Derive and figure out the kind dynamically
            _kind = EntityTypeMappingKind.Derive;

            ClearEFObjectCollection(_fragments);

            ClearEFObject(_modificationFunctionMapping);
            _modificationFunctionMapping = null;

            base.PreParse();
        }
 internal bool UsesEntityTypeMappingKind(EntityTypeMappingKind kind)
 {
     return(EntityTypeMappingKind == kind);
 }
 /// <summary>
 ///     A constructor to call when we are creating a new ETM.  If you send a specific kind to this
 ///     constructor then this will be used [for deriving RefNames for instance; see EntityType.GetRefNameForBinding()]
 ///     until the item is parsed.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="element"></param>
 /// <param name="kind"></param>
 internal EntityTypeMapping(EFContainer parent, XElement element, EntityTypeMappingKind kind)
     : base(parent, element)
 {
     Debug.Assert(parent is EntitySetMapping, "parent should be a EntitySetMapping");
     _kind = kind;
 }
Esempio n. 20
0
 /// <summary>
 ///     A constructor to call when we are creating a new ETM.  If you send a specific kind to this
 ///     constructor then this will be used [for deriving RefNames for instance; see EntityType.GetRefNameForBinding()]
 ///     until the item is parsed.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="element"></param>
 /// <param name="kind"></param>
 internal EntityTypeMapping(EFContainer parent, XElement element, EntityTypeMappingKind kind)
     : base(parent, element)
 {
     Debug.Assert(parent is EntitySetMapping, "parent should be a EntitySetMapping");
     _kind = kind;
 }