public DataAssociationLink(IDataEntityComplexProperty owner, string name, string role)
 {
     _owner     = owner;
     _name      = name;
     _role      = role;
     _principal = _foreign = null;
 }
Ejemplo n.º 2
0
        public DataAssociationLink(IDataEntityComplexProperty owner, string foreign, string anchor = null)
        {
            if (string.IsNullOrEmpty(foreign))
            {
                throw new ArgumentNullException(nameof(foreign));
            }

            _owner      = owner ?? throw new ArgumentNullException(nameof(owner));
            _foreign    = foreign;
            _anchor     = string.IsNullOrEmpty(anchor) ? foreign : anchor;
            _foreignKey = null;
        }
Ejemplo n.º 3
0
        public DataEntityPropertySequence(IDataEntitySimplexProperty property, string name, int seed, int interval = 1, IList <string> references = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.Property = property ?? throw new ArgumentNullException(nameof(property));
            this.Name     = name.Trim();
            this.Seed     = seed;
            this.Interval = interval == 0 ? 1 : interval;

            if (this.Name == "#")
            {
                this.Name = "#" + property.Entity.Name + ":" + property.Name;
            }

            _referenceNames = references;
        }
Ejemplo n.º 4
0
        private bool IsLinked(SchemaMember owner, IDataEntitySimplexProperty property)
        {
            if (owner == null || owner.Token.Property.IsSimplex)
            {
                return(false);
            }

            var links = ((IDataEntityComplexProperty)owner.Token.Property).Links;

            for (int i = 0; i < links.Length; i++)
            {
                if (object.Equals(links[i].Foreign, property))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// 创建一个字段定义并添加到当前表定义的 <see cref="Fields"/> 集中,如果同名字段已经定义则返回空(null)。
		/// </summary>
		/// <param name="property">指定的要添加字段的单值属性元信息。</param>
		/// <returns>返回的新增字段定义项,如果指定属性对应的字段已经存在则返回空(null)。</returns>
		public FieldDefinition Field(IDataEntitySimplexProperty property)
		{
			if(property == null)
				throw new ArgumentNullException(nameof(property));

			var fieldName = property.GetFieldName(out _);

			if(this.Fields.Contains(fieldName))
				return null;

			var field = new FieldDefinition(fieldName, property.Type, property.Nullable)
			{
				Length = property.Length,
				Precision = property.Precision,
				Scale = property.Scale,
			};

			this.Fields.Add(field);
			return field;
		}
Ejemplo n.º 6
0
        private IDataEntity ResolveEntity(XmlReader reader, MetadataFile provider, string @namespace, Action unrecognize)
        {
            //创建实体元素对象
            var entity = new MetadataEntity(provider,
                                            this.GetFullName(reader.GetAttribute(XML_NAME_ATTRIBUTE), @namespace),
                                            this.GetFullName(reader.GetAttribute(XML_INHERITS_ATTRIBUTE), @namespace),
                                            this.GetAttributeValue(reader, XML_IMMUTABLE_ATTRIBUTE, false));

            //设置其他属性
            entity.Alias = reader.GetAttribute(XML_ALIAS_ATTRIBUTE) ?? reader.GetAttribute(XML_TABLE_ATTRIBUTE);

            var keys  = new HashSet <string>();
            int depth = reader.Depth;

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

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

                        if (reader.Name == XML_MEMBER_ELEMENT)
                        {
                            keys.Add(reader.GetAttribute(XML_NAME_ATTRIBUTE));
                        }
                        else
                        {
                            unrecognize();
                        }
                    }

                    break;

                case XML_PROPERTY_ELEMENT:
                    var property = new MetadataEntitySimplexProperty(entity,
                                                                     reader.GetAttribute(XML_NAME_ATTRIBUTE),
                                                                     this.GetFieldType(this.GetAttributeValue <string>(reader, XML_TYPE_ATTRIBUTE)),
                                                                     this.GetAttributeValue(reader, XML_IMMUTABLE_ATTRIBUTE, false))
                    {
                        Alias     = this.GetAttributeValue <string>(reader, XML_ALIAS_ATTRIBUTE) ?? this.GetAttributeValue <string>(reader, XML_FIELD_ATTRIBUTE),
                        Length    = this.GetAttributeValue <int>(reader, XML_LENGTH_ATTRIBUTE),
                        Precision = this.GetAttributeValue <byte>(reader, XML_PRECISION_ATTRIBUTE),
                        Scale     = this.GetAttributeValue <byte>(reader, XML_SCALE_ATTRIBUTE),
                        Nullable  = this.GetAttributeValue <bool>(reader, XML_NULLABLE_ATTRIBUTE, true),
                        Sortable  = this.GetAttributeValue <bool>(reader, XML_SORTABLE_ATTRIBUTE, false),
                    };

                    //设置默认值的字面量
                    property.SetDefaultValue(this.GetAttributeValue <string>(reader, XML_DEFAULT_ATTRIBUTE));

                    //设置序号器元数据信息
                    property.SetSequence(this.GetAttributeValue <string>(reader, XML_SEQUENCE_ATTRIBUTE));

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

                    break;

                case XML_COMPLEXPROPERTY_ELEMENT:
                    var complexProperty = new MetadataEntityComplexProperty(entity,
                                                                            reader.GetAttribute(XML_NAME_ATTRIBUTE),
                                                                            this.GetRoleName(reader.GetAttribute(XML_ROLE_ATTRIBUTE), @namespace),
                                                                            this.GetAttributeValue(reader, XML_IMMUTABLE_ATTRIBUTE, false));

                    var multiplicity = reader.GetAttribute(XML_MULTIPLICITY_ATTRIBUTE);

                    if (multiplicity != null && multiplicity.Length > 0)
                    {
                        switch (multiplicity)
                        {
                        case "*":
                            complexProperty.Multiplicity = DataAssociationMultiplicity.Many;
                            break;

                        case "1":
                        case "!":
                            complexProperty.Multiplicity = DataAssociationMultiplicity.One;
                            break;

                        case "?":
                        case "0..1":
                            complexProperty.Multiplicity = DataAssociationMultiplicity.ZeroOrOne;
                            break;

                        default:
                            throw new DataException($"Invalid '{multiplicity}' value of the multiplicity attribute.");
                        }
                    }

                    var links = new List <DataAssociationLink>();

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

                        if (reader.LocalName == XML_LINK_ELEMENT)
                        {
                            links.Add(
                                new DataAssociationLink(complexProperty,
                                                        this.GetAttributeValue <string>(reader, XML_NAME_ATTRIBUTE),
                                                        this.GetAttributeValue <string>(reader, XML_ROLE_ATTRIBUTE)));
                        }
                        else if (reader.LocalName == XML_CONSTRAINTS_ELEMENT)
                        {
                            if (reader.IsEmptyElement)
                            {
                                continue;
                            }

                            var constraints = new List <DataAssociationConstraint>();

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

                                if (reader.LocalName == XML_CONSTRAINT_ELEMENT)
                                {
                                    constraints.Add(
                                        new DataAssociationConstraint(
                                            this.GetAttributeValue <string>(reader, XML_NAME_ATTRIBUTE),
                                            this.GetAttributeValue(reader, XML_ACTOR_ATTRIBUTE, DataAssociationConstraintActor.Principal),
                                            this.GetAttributeValue <object>(reader, XML_VALUE_ATTRIBUTE)));
                                }
                                else
                                {
                                    unrecognize();
                                }
                            }

                            if (constraints.Count > 0)
                            {
                                complexProperty.Constraints = constraints.ToArray();
                            }
                        }
                        else
                        {
                            unrecognize();
                        }
                    }

                    if (links == null || links.Count == 0)
                    {
                        throw new DataException($"Missing links of the '{complexProperty.Name}' complex property in the '{provider.FilePath}' mapping file.");
                    }

                    //设置复合属性的链接集属性
                    complexProperty.Links = links.ToArray();

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

                    break;

                default:
                    unrecognize();
                    break;
                }
            }

            //确认实体的主键信息
            if (keys.Count > 0)
            {
                var array = new IDataEntitySimplexProperty[keys.Count];
                var index = 0;

                foreach (var key in keys)
                {
                    if (!entity.Properties.TryGet(key, out var property))
                    {
                        throw new MetadataFileException($"The '{key}' primary key in the '{entity.Name}' entity is undefined.");
                    }
                    if (property.IsComplex)
                    {
                        throw new MetadataFileException($"The '{key}' primary key in the '{entity.Name}' entity cannot be a complex(navigation) property.");
                    }

                    //将主键属性的是否主键开关打开
                    ((MetadataEntitySimplexProperty)property).SetPrimaryKey();

                    array[index++] = (IDataEntitySimplexProperty)property;
                }

                entity.Key = array;
            }

            return(entity);
        }
 public Proxy(IDataEntitySimplexProperty host, string destinationEntity, string destinationProperty)
 {
     _host = host ?? throw new ArgumentNullException(nameof(host));
     _destinationEntity   = destinationEntity;
     _destinationProperty = destinationProperty;
 }
Ejemplo n.º 8
0
 public LinkToken(IDataEntitySimplexProperty foreign, object value)
 {
     this.ForeignProperty = foreign;
     this.PrincipalValue  = value;
 }