Esempio n. 1
0
            public RelationshipElement(MetadataEntityComplexProperty owner, string associationName, string principal, string dependent)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner");
                }

                if (string.IsNullOrWhiteSpace(associationName))
                {
                    throw new ArgumentNullException("associationName");
                }

                _owner           = owner;
                _associationName = associationName.Trim();
                _from            = principal;
                _to = dependent;
            }
Esempio n. 2
0
        private void ResolveEntity(XmlReader reader, MetadataContainerBase container)
        {
            //创建实体元素对象
            var entity = container.CreateEntity(reader.GetAttribute(XML_NAME_ATTRIBUTE));

            //设置实体元素的基类名
            entity.BaseEntityName = reader.GetAttribute(XML_INHERITS_ATTRIBUTE);

            //处理实体元素的所有其他未知属性
            this.ProcessAttributes(reader, entity, (element, prefix, localName, value, namespaceUri) =>
            {
                return((localName == XML_NAME_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)) ||
                       (localName == XML_INHERITS_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)));
            });

            int depth = reader.Depth;

            while (reader.Read() && reader.Depth > depth)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (reader.Name)
                {
                case XML_KEY_ELEMENT:
                    while (reader.Read() && reader.Depth > depth + 1)
                    {
                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }

                        if (reader.Name == XML_PROPERTYREF_ELEMENT)
                        {
                            entity.SetKey(reader.GetAttribute(XML_NAME_ATTRIBUTE));
                        }
                        else
                        {
                            this.ProcessUnrecognizedElement(reader, null, container);
                        }
                    }

                    break;

                case XML_PROPERTY_ELEMENT:
                    var property = new MetadataEntitySimplexProperty(reader.GetAttribute(XML_NAME_ATTRIBUTE), reader.GetAttribute(XML_TYPE_ATTRIBUTE))
                    {
                        Length    = this.GetAttributeValue <int>(reader, XML_LENGTH_ATTRIBUTE),
                        Nullable  = this.GetAttributeValue <bool>(reader, XML_NULLABLE_ATTRIBUTE),
                        Precision = this.GetAttributeValue <byte>(reader, XML_PRECISION_ATTRIBUTE),
                        Scale     = this.GetAttributeValue <byte>(reader, XML_SCALE_ATTRIBUTE),
                    };

                    //处理属性元素的所有其他未知属性
                    this.ProcessAttributes(reader, property, (element, prefix, localName, value, namespaceUri) =>
                    {
                        return((localName == XML_LENGTH_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)) ||
                               (localName == XML_NULLABLE_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)) ||
                               (localName == XML_PRECISION_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)) ||
                               (localName == XML_SCALE_ATTRIBUTE && string.IsNullOrEmpty(namespaceUri)));
                    });

                    //将解析成功的属性元素加入到实体的属性集合
                    entity.Properties.Add(property);

                    break;

                case XML_COMPLEXPROPERTY_ELEMENT:
                    var complexProperty = new MetadataEntityComplexProperty(
                        reader.GetAttribute(XML_NAME_ATTRIBUTE),
                        reader.GetAttribute(XML_RELATIONSHIP_ATTRIBUTE),
                        reader.GetAttribute(XML_FROM_ATTRIBUTE),
                        reader.GetAttribute(XML_TO_ATTRIBUTE));

                    //将解析成功的属性元素加入到实体的属性集合
                    entity.Properties.Add(complexProperty);

                    break;

                default:
                    this.ProcessUnrecognizedElement(reader, null, container);
                    break;
                }
            }

            switch (container.Kind)
            {
            case MetadataElementKind.Concept:
                ((MetadataConceptContainer)container).Entities.Add((MetadataConceptEntity)entity);
                break;

            case MetadataElementKind.Storage:
                ((MetadataStorageContainer)container).Entities.Add((MetadataStorageEntity)entity);
                break;
            }
        }