public void AddEntityTypeMappingFragment(
            EntitySet entitySet, EntityType entityType, MappingFragment fragment)
        {
            Debug.Assert(fragment.Table == Table);

            _entityTypes.Add(entitySet, entityType);

            var defaultDiscriminatorColumn = fragment.GetDefaultDiscriminator();
            ConditionPropertyMapping defaultDiscriminatorCondition = null;

            if (defaultDiscriminatorColumn != null)
            {
                defaultDiscriminatorCondition =
                    fragment.ColumnConditions.SingleOrDefault(cc => cc.Column == defaultDiscriminatorColumn);
            }

            foreach (var pm in fragment.ColumnMappings)
            {
                var columnMapping = FindOrCreateColumnMapping(pm.ColumnProperty);
                columnMapping.AddMapping(
                    entityType,
                    pm.PropertyPath,
                    fragment.ColumnConditions.Where(cc => cc.Column == pm.ColumnProperty),
                    defaultDiscriminatorColumn == pm.ColumnProperty);
            }

            // Add any column conditions that aren't mapped to properties
            foreach (
                var cc in
                fragment.ColumnConditions.Where(cc => !fragment.ColumnMappings.Any(pm => pm.ColumnProperty == cc.Column)))
            {
                var columnMapping = FindOrCreateColumnMapping(cc.Column);
                columnMapping.AddMapping(entityType, null, new[] { cc }, defaultDiscriminatorColumn == cc.Column);
            }
        }
示例#2
0
        // <summary>
        // Takes in a JoinTreeNode and a Contition Property Map and creates an BoolExpression
        // for the Condition Map.
        // </summary>
        private static BoolExpression GetConditionExpression(MemberPath member, ConditionPropertyMapping conditionMap)
        {
            //Get the member for which the condition is being specified
            EdmMember conditionMember = (conditionMap.Column != null) ? conditionMap.Column : conditionMap.Property;

            var conditionMemberNode = new MemberPath(member, conditionMember);
            //Check if this is a IsNull condition
            MemberRestriction conditionExpression = null;

            if (conditionMap.IsNull.HasValue)
            {
                // for conditions on scalars, create NodeValue nodes, otherwise NodeType
                var conditionConstant = conditionMap.IsNull.Value ? Constant.Null : Constant.NotNull;
                if (MetadataHelper.IsNonRefSimpleMember(conditionMember))
                {
                    conditionExpression = new ScalarRestriction(conditionMemberNode, conditionConstant);
                }
                else
                {
                    conditionExpression = new TypeRestriction(conditionMemberNode, conditionConstant);
                }
            }
            else
            {
                conditionExpression = new ScalarRestriction(conditionMemberNode, new ScalarConstant(conditionMap.Value));
            }

            Debug.Assert(conditionExpression != null);

            return(BoolExpression.CreateLiteral(conditionExpression, null));
        }
示例#3
0
 private void ExtractProperties(
     IEnumerable <PropertyMapping> properties,
     MemberPath cNode,
     List <ProjectedSlot> cSlots,
     ref BoolExpression cQueryWhereClause,
     MemberPath sRootExtent,
     List <ProjectedSlot> sSlots,
     ref BoolExpression sQueryWhereClause)
 {
     foreach (PropertyMapping property in properties)
     {
         ScalarPropertyMapping    scalarPropertyMapping  = property as ScalarPropertyMapping;
         ComplexPropertyMapping   complexPropertyMapping = property as ComplexPropertyMapping;
         EndPropertyMapping       endPropertyMapping     = property as EndPropertyMapping;
         ConditionPropertyMapping conditionMap           = property as ConditionPropertyMapping;
         if (scalarPropertyMapping != null)
         {
             MemberPath node1 = new MemberPath(cNode, (EdmMember)scalarPropertyMapping.Property);
             MemberPath node2 = new MemberPath(sRootExtent, (EdmMember)scalarPropertyMapping.Column);
             cSlots.Add((ProjectedSlot) new MemberProjectedSlot(node1));
             sSlots.Add((ProjectedSlot) new MemberProjectedSlot(node2));
         }
         if (complexPropertyMapping != null)
         {
             foreach (ComplexTypeMapping typeMapping in complexPropertyMapping.TypeMappings)
             {
                 MemberPath            memberPath = new MemberPath(cNode, (EdmMember)complexPropertyMapping.Property);
                 Set <EdmType>         set        = new Set <EdmType>();
                 IEnumerable <EdmType> elements   = Helpers.AsSuperTypeList <ComplexType, EdmType>((IEnumerable <ComplexType>)typeMapping.Types);
                 set.AddRange(elements);
                 foreach (EdmType isOfType in typeMapping.IsOfTypes)
                 {
                     set.AddRange(MetadataHelper.GetTypeAndSubtypesOf(isOfType, (ItemCollection)this.m_containerMapping.StorageMappingItemCollection.EdmItemCollection, false));
                 }
                 BoolExpression literal = BoolExpression.CreateLiteral((BoolLiteral) new TypeRestriction(memberPath, (IEnumerable <EdmType>)set), (MemberDomainMap)null);
                 cQueryWhereClause = BoolExpression.CreateAnd(cQueryWhereClause, literal);
                 this.ExtractProperties((IEnumerable <PropertyMapping>)typeMapping.AllProperties, memberPath, cSlots, ref cQueryWhereClause, sRootExtent, sSlots, ref sQueryWhereClause);
             }
         }
         if (endPropertyMapping != null)
         {
             MemberPath cNode1 = new MemberPath(cNode, (EdmMember)endPropertyMapping.AssociationEnd);
             this.ExtractProperties((IEnumerable <PropertyMapping>)endPropertyMapping.PropertyMappings, cNode1, cSlots, ref cQueryWhereClause, sRootExtent, sSlots, ref sQueryWhereClause);
         }
         if (conditionMap != null)
         {
             if (conditionMap.Column != null)
             {
                 BoolExpression conditionExpression = CellCreator.GetConditionExpression(sRootExtent, conditionMap);
                 sQueryWhereClause = BoolExpression.CreateAnd(sQueryWhereClause, conditionExpression);
             }
             else
             {
                 BoolExpression conditionExpression = CellCreator.GetConditionExpression(cNode, conditionMap);
                 cQueryWhereClause = BoolExpression.CreateAnd(cQueryWhereClause, conditionExpression);
             }
         }
     }
 }
 private void WriteConditionElement(ConditionPropertyMapping condition)
 {
     this._xmlWriter.WriteStartElement("Condition");
     if (condition.IsNull.HasValue)
     {
         this.WriteIsNullConditionAttribute(condition.IsNull.Value);
     }
     else
     {
         this.WriteConditionValue(condition.Value);
     }
     this._xmlWriter.WriteAttributeString("ColumnName", condition.Column.Name);
     this._xmlWriter.WriteEndElement();
 }
示例#5
0
        private void WriteConditionElement(ConditionPropertyMapping condition)
        {
            DebugCheck.NotNull(condition);

            _xmlWriter.WriteStartElement(MslConstructs.ConditionElement);
            if (condition.IsNull.HasValue)
            {
                WriteIsNullConditionAttribute(condition.IsNull.Value);
            }
            else
            {
                WriteConditionValue(condition.Value);
            }
            _xmlWriter.WriteAttributeString(MslConstructs.ConditionColumnNameAttribute, condition.Column.Name);
            _xmlWriter.WriteEndElement();
        }
示例#6
0
        private static void CopyDefaultDiscriminator(
            MappingFragment fromFragment,
            MappingFragment toFragment)
        {
            EdmProperty discriminatorColumn = fromFragment.GetDefaultDiscriminator();

            if (discriminatorColumn == null)
            {
                return;
            }
            ConditionPropertyMapping conditionPropertyMapping = fromFragment.ColumnConditions.SingleOrDefault <ConditionPropertyMapping>((Func <ConditionPropertyMapping, bool>)(cc => cc.Column == discriminatorColumn));

            if (conditionPropertyMapping == null)
            {
                return;
            }
            toFragment.AddDiscriminatorCondition(conditionPropertyMapping.Column, conditionPropertyMapping.Value);
            toFragment.SetDefaultDiscriminator(conditionPropertyMapping.Column);
        }
示例#7
0
        private static BoolExpression GetConditionExpression(
            MemberPath member,
            ConditionPropertyMapping conditionMap)
        {
            EdmMember         edmMember = conditionMap.Column != null ? (EdmMember)conditionMap.Column : (EdmMember)conditionMap.Property;
            MemberPath        member1   = new MemberPath(member, edmMember);
            MemberRestriction memberRestriction;

            if (conditionMap.IsNull.HasValue)
            {
                Constant constant = conditionMap.IsNull.Value ? Constant.Null : Constant.NotNull;
                memberRestriction = !MetadataHelper.IsNonRefSimpleMember(edmMember) ? (MemberRestriction) new TypeRestriction(member1, constant) : (MemberRestriction) new ScalarRestriction(member1, constant);
            }
            else
            {
                memberRestriction = (MemberRestriction) new ScalarRestriction(member1, (Constant) new ScalarConstant(conditionMap.Value));
            }
            return(BoolExpression.CreateLiteral((BoolLiteral)memberRestriction, (MemberDomainMap)null));
        }
        private void WriteConditionElement(ConditionPropertyMapping condition)
        {
            DebugCheck.NotNull(condition);

            _xmlWriter.WriteStartElement(MslConstructs.ConditionElement);
            if (condition.IsNull.HasValue)
            {
                _xmlWriter.WriteAttributeString(
                    MslConstructs.ConditionIsNullAttribute, GetLowerCaseStringFromBoolValue(condition.IsNull.Value));
            }
            else
            {
                if (condition.Value is bool)
                {
                    _xmlWriter.WriteAttributeString(MslConstructs.ConditionValueAttribute, (bool)condition.Value ? "1" : "0");
                }
                else
                {
                    _xmlWriter.WriteAttributeString(MslConstructs.ConditionValueAttribute, condition.Value.ToString());
                }
            }
            _xmlWriter.WriteAttributeString(MslConstructs.ConditionColumnNameAttribute, condition.Column.Name);
            _xmlWriter.WriteEndElement();
        }
示例#9
0
        // <summary>
        // Takes in a JoinTreeNode and a Contition Property Map and creates an BoolExpression
        // for the Condition Map.
        // </summary>
        private static BoolExpression GetConditionExpression(MemberPath member, ConditionPropertyMapping conditionMap)
        {
            //Get the member for which the condition is being specified
            EdmMember conditionMember = (conditionMap.Column != null) ? conditionMap.Column : conditionMap.Property;

            var conditionMemberNode = new MemberPath(member, conditionMember);
            //Check if this is a IsNull condition
            MemberRestriction conditionExpression = null;
            if (conditionMap.IsNull.HasValue)
            {
                // for conditions on scalars, create NodeValue nodes, otherwise NodeType
                var conditionConstant = conditionMap.IsNull.Value ? Constant.Null : Constant.NotNull;
                if (MetadataHelper.IsNonRefSimpleMember(conditionMember))
                {
                    conditionExpression = new ScalarRestriction(conditionMemberNode, conditionConstant);
                }
                else
                {
                    conditionExpression = new TypeRestriction(conditionMemberNode, conditionConstant);
                }
            }
            else
            {
                conditionExpression = new ScalarRestriction(conditionMemberNode, new ScalarConstant(conditionMap.Value));
            }

            Debug.Assert(conditionExpression != null);

            return BoolExpression.CreateLiteral(conditionExpression, null);
        }