コード例 #1
0
ファイル: ComplexProperty.cs プロジェクト: dotnet/ef6tools
 internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == ScalarProperty.ElementName)
     {
         var prop = new ScalarProperty(this, elem);
         _scalarProperties.Add(prop);
         prop.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == ElementName)
     {
         var complexProperty = new ComplexProperty(this, elem);
         _complexProperties.Add(complexProperty);
         complexProperty.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == ComplexTypeMapping.ElementName)
     {
         var complexTypeMapping = new ComplexTypeMapping(this, elem);
         _complexTypeMappings.Add(complexTypeMapping);
         complexTypeMapping.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == Condition.ElementName)
     {
         var cond = new Condition(this, elem);
         _conditions.Add(cond);
         cond.Parse(unprocessedElements);
     }
     else
     {
         return(base.ParseSingleElement(unprocessedElements, elem));
     }
     return(true);
 }
コード例 #2
0
 internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == ScalarProperty.ElementName)
     {
         var sp = new ScalarProperty(this, elem);
         _properties.Add(sp);
         sp.Parse(unprocessedElements);
     }
     else
     {
         return(base.ParseSingleElement(unprocessedElements, elem));
     }
     return(true);
 }
コード例 #3
0
        public MappingScalarProperty(EditingContext context, ScalarProperty scalarProperty, MappingEFElement parent)
            : base(context, scalarProperty, parent)
        {
            if (scalarProperty != null)
            {
                if (scalarProperty.ColumnName.Status == BindingStatus.Known)
                {
                    _columnName = scalarProperty.ColumnName.Target.LocalName.Value;
                }
                else
                {
                    _columnName = scalarProperty.ColumnName.RefName;
                }
            }

            _columnType = Resources.MappingDetails_UnknownColumnType;
        }
コード例 #4
0
        /// <summary>
        ///     Changes one or both of the ends of an existing ScalarProperty.  You can send
        ///     null to one of the ends, but both cannot be null.
        /// </summary>
        /// <param name="sp">A valid Scalar Property; this cannot be null.</param>
        /// <param name="entityProperty">The C-Side property to change to.</param>
        /// <param name="tableColumn">The S-Side property to change to.</param>
        internal ChangeScalarPropertyCommand(ScalarProperty sp, Property entityProperty, Property tableColumn)
        {
            CommandValidation.ValidateScalarProperty(sp);

            Debug.Assert(entityProperty != null || tableColumn != null, "At least one of entityProperty or tableColumn should be non-null");
            if (entityProperty != null)
            {
                CommandValidation.ValidateConceptualEntityProperty(entityProperty);
            }
            if (tableColumn != null)
            {
                CommandValidation.ValidateTableColumn(tableColumn);
            }

            ScalarProperty = sp;
            _entityProperty = entityProperty;
            TableColumn = tableColumn;
        }
コード例 #5
0
 protected override void BuildExisting(CommandProcessorContext cpc, ScalarProperty scalarProperty)
 {
     var mesp = (MappingEndScalarProperty)ModelToMappingModelXRef.GetNewOrExisting(cpc.EditingContext, scalarProperty, _mase);
     _mase._scalarProperties.Add(mesp);
 }
コード例 #6
0
 internal static void AddRule(CommandProcessorContext cpc, ScalarProperty element)
 {
     if (element != null)
     {
         AddRule(cpc, element.MappingFragment.EntityTypeMapping.EntitySetMapping);
     }
 }
コード例 #7
0
 internal void AddScalarProperty(ScalarProperty sp)
 {
     _properties.Add(sp);
 }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(
                _mode == Mode.EntityType || _mode == Mode.MappingFragment, "Unknown mode set in CreateFragmentScalarPropertyTreeCommand");

            var cp = new CommandProcessor(cpc);
            CreateFragmentComplexPropertyCommand prereqCmd = null;
            for (var i = 0; i < _properties.Count; i++)
            {
                var property = _properties[i];
                var complexConceptualProperty = property as ComplexConceptualProperty;
                if (complexConceptualProperty != null)
                {
                    Debug.Assert(i < _properties.Count - 1, "Last property shouldn't be ComplexConceptualProperty");
                    CreateFragmentComplexPropertyCommand cmd = null;
                    if (prereqCmd == null)
                    {
                        if (_mode == Mode.EntityType)
                        {
                            cmd = new CreateFragmentComplexPropertyCommand(_conceptualEntityType, complexConceptualProperty, _tableColumn);
                        }
                        else
                        {
                            cmd = new CreateFragmentComplexPropertyCommand(_mappingFragment, complexConceptualProperty);
                        }
                    }
                    else
                    {
                        cmd = new CreateFragmentComplexPropertyCommand(prereqCmd, complexConceptualProperty);
                    }

                    prereqCmd = cmd;
                    cp.EnqueueCommand(cmd);
                }
                else
                {
                    Debug.Assert(i == _properties.Count - 1, "This should be the last property");
                    CreateFragmentScalarPropertyCommand cmd = null;
                    if (prereqCmd == null)
                    {
                        if (_mode == Mode.EntityType)
                        {
                            cmd = new CreateFragmentScalarPropertyCommand(_conceptualEntityType, property, _tableColumn);
                        }
                        else
                        {
                            cmd = new CreateFragmentScalarPropertyCommand(_mappingFragment, property, _tableColumn);
                        }
                    }
                    else
                    {
                        cmd = new CreateFragmentScalarPropertyCommand(prereqCmd, property, _tableColumn);
                    }

                    cp.EnqueueCommand(cmd);
                    cp.Invoke();
                    _createdProperty = cmd.ScalarProperty;
                    return;
                }
            }
        }
コード例 #9
0
        private static ScalarProperty CreateNewScalarProperty(EFElement parent, Property entityProperty, Property tableColumn)
        {
            // actually create it in the XLinq tree
            var sp = new ScalarProperty(parent, null);
            sp.Name.SetRefName(entityProperty);
            sp.ColumnName.SetRefName(tableColumn);

            XmlModelHelper.NormalizeAndResolve(sp);

            if (sp == null)
            {
                throw new ItemCreationFailureException();
            }

            Debug.Assert(sp.Name.Target != null && sp.Name.Target.LocalName.Value == sp.Name.RefName, "Broken entity property resolution");
            Debug.Assert(
                sp.ColumnName.Target != null && sp.ColumnName.Target.LocalName.Value == sp.ColumnName.RefName, "Broken column resolution");

            return sp;
        }
コード例 #10
0
 internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == ScalarProperty.ElementName)
     {
         var sp = new ScalarProperty(this, elem);
         _properties.Add(sp);
         sp.Parse(unprocessedElements);
     }
     else
     {
         return base.ParseSingleElement(unprocessedElements, elem);
     }
     return true;
 }
コード例 #11
0
        private static Property GetMappedProperty(ScalarProperty scalarProperty)
        {
            Property entityProperty = null;
            var complexProperty = scalarProperty.GetTopMostComplexProperty();
            if (complexProperty == null)
            {
                entityProperty = scalarProperty.Name.Target;
            }
            else
            {
                entityProperty = complexProperty.Name.Target;
            }

            return entityProperty;
        }
コード例 #12
0
        private static void GetInheritanceScalarPropsForStorageProp(
            Property storageProp, ConceptualEntityType etmEntityType, out ScalarProperty scalarPropMappedToCurrentEntity,
            out ScalarProperty nearestScalarPropMappedToAncestorEntity)
        {
            scalarPropMappedToCurrentEntity = null;
            nearestScalarPropMappedToAncestorEntity = null;

            // assign the ScalarProp which maps storageProp within ETM where the EntityType is etmEntityType (can be null)
            scalarPropMappedToCurrentEntity = storageProp.GetAntiDependenciesOfType<ScalarProperty>().
                FirstOrDefault<ScalarProperty>(scalarProp => scalarProp.FirstBoundConceptualEntityType == etmEntityType);

            // assign the ScalarProp which maps storageProp within ETM for nearest ancestor of etmEntityType (can be null)
            foreach (var cet in etmEntityType.ResolvableBaseTypes)
            {
                nearestScalarPropMappedToAncestorEntity = storageProp.GetAntiDependenciesOfType<ScalarProperty>().
                    FirstOrDefault<ScalarProperty>(scalarProp => scalarProp.FirstBoundConceptualEntityType == cet);
                if (nearestScalarPropMappedToAncestorEntity != null)
                {
                    return;
                }
            }
        }
コード例 #13
0
 public MappingEndScalarProperty(EditingContext context, ScalarProperty sp, MappingEFElement parent)
     : base(context, sp, parent)
 {
     _propertyType = Resources.MappingDetails_UnknownColumnType;
 }
コード例 #14
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (_endProperty == null)
            {
                var cmd = new CreateEndPropertyCommand(_associationSetMapping, _associationSetEnd);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _endProperty = cmd.EndProperty;
            }

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

            var sp = new ScalarProperty(_endProperty, null);
            sp.Name.SetRefName(_entityProperty);
            sp.ColumnName.SetRefName(_tableColumn);
            _endProperty.AddScalarProperty(sp);

            XmlModelHelper.NormalizeAndResolve(sp);

            if (_enforceConstraints)
            {
                var asm = _endProperty.Parent as AssociationSetMapping;
                Debug.Assert(asm != null, "_endProperty parent is not an AssociationSetMapping");
                EnforceAssociationSetMappingRules.AddRule(cpc, asm);

                var assoc = asm.TypeName.Target;
                Debug.Assert(assoc != null, "_endProperty parent has a null Association");
                if (assoc != null)
                {
                    InferReferentialConstraints.AddRule(cpc, assoc);
                }
            }

            _created = sp;
        }
コード例 #15
0
 internal void AddScalarProperty(ScalarProperty prop)
 {
     _scalarProperties.Add(prop);
 }
コード例 #16
0
 internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == ScalarProperty.ElementName)
     {
         var prop = new ScalarProperty(this, elem);
         _scalarProperties.Add(prop);
         prop.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == ComplexProperty.ElementName)
     {
         var prop = new ComplexProperty(this, elem);
         _complexProperties.Add(prop);
         prop.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == Condition.ElementName)
     {
         var cond = new Condition(this, elem);
         _conditions.Add(cond);
         cond.Parse(unprocessedElements);
     }
     else
     {
         return base.ParseSingleElement(unprocessedElements, elem);
     }
     return true;
 }
コード例 #17
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(
                ModeValue == Mode.EntityType || ModeValue == Mode.MappingFragment || ModeValue == Mode.ComplexProperty,
                "Unknown mode set in CreateFragmentScalarPropertyCommand");

            if (ModeValue == Mode.EntityType)
            {
                // safety check, this should never be hit
                if (ConceptualEntityType == null
                    || Property == null
                    || TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingEntity(
                    cpc,
                    ConceptualEntityType, Property, TableColumn);
            }
            else if (ModeValue == Mode.ComplexProperty)
            {
                // safety check, this should never be hit
                if (ComplexProperty == null
                    || Property == null
                    || TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingComplexProperty(ComplexProperty, Property, TableColumn);
            }
            else
            {
                // safety check, this should never be hit
                if (_mappingFragment == null
                    || Property == null
                    || TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingFragment(_mappingFragment, Property, TableColumn);
            }

            if (_sp.MappingFragment != null
                && _sp.MappingFragment.EntityTypeMapping != null
                && _sp.MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType != null)
            {
                PropagateViewKeysToStorageModel.AddRule(cpc, _sp.MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType);

                // Also add the integrity check to propagate the StoreGeneratedPattern value to the
                // S-side (may be altered by property being/not being mapped) unless we are part
                // of an Update Model txn in which case there is no need as the whole artifact has
                // this integrity check applied by UpdateModelFromDatabaseCommand
                if (EfiTransactionOriginator.UpdateModelFromDatabaseId != cpc.OriginatorId
                    && _sp.Name != null
                    && _sp.Name.Target != null)
                {
                    var cProp = _sp.Name.Target as ConceptualProperty;
                    Debug.Assert(
                        cProp != null,
                        " ScalarProperty should have Name target with type ConceptualProperty, instead got type "
                        + _sp.Name.Target.GetType().FullName);
                    if (cProp != null)
                    {
                        PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, cProp, true);
                    }
                }
            }
        }
コード例 #18
0
 internal void AddScalarProperty(ScalarProperty sp)
 {
     _properties.Add(sp);
 }
 private void PreserveScalarPropertyMapping(
     CommandProcessorContext cpc, ScalarProperty scalarPropertyMapping, Property createdComplexTypeProperty)
 {
     // this represents a path to a scalar Property in the original EntityType properties tree
     var propertiesChain = scalarPropertyMapping.GetMappedPropertiesList();
     // we need to create a corresponding path in changed EntityType
     // in order to do that we need to replace first (root) item with a created property from ComplexType...
     propertiesChain.RemoveAt(0);
     propertiesChain.Insert(0, createdComplexTypeProperty);
     // and add the created EntityType complex property as a root of that path
     propertiesChain.Insert(0, _createdComplexProperty);
     var cmd = new CreateFragmentScalarPropertyTreeCommand(_entityType, propertiesChain, scalarPropertyMapping.ColumnName.Target);
     CommandProcessor.InvokeSingleCommand(cpc, cmd);
 }
コード例 #20
0
 /// <summary>
 ///     Deletes the passed in ScalarProperty
 /// </summary>
 /// <param name="sp"></param>
 internal DeleteScalarPropertyCommand(ScalarProperty sp)
     : base(sp)
 {
     CommandValidation.ValidateScalarProperty(sp);
 }
コード例 #21
0
ファイル: ComplexProperty.cs プロジェクト: dotnet/ef6tools
 internal void AddScalarProperty(ScalarProperty prop)
 {
     _scalarProperties.Add(prop);
 }
コード例 #22
0
 internal static void ValidateScalarProperty(ScalarProperty sp)
 {
     ValidateEFElement(sp);
 }