public AssociationLink(IEntityComplexPropertyMetadata owner, string name, string role)
 {
     _owner     = owner;
     _name      = name;
     _role      = role;
     _principal = _foreign = null;
 }
Beispiel #2
0
        private bool IsLinked(IEntityComplexPropertyMetadata owner, IEntitySimplexPropertyMetadata property)
        {
            var links = owner.Links;

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

            return(false);
        }
Beispiel #3
0
        private static IEntityPropertyMetadataCollection GetAssociatedProperties(IEntityComplexPropertyMetadata property, ref ICollection <IEntityMetadata> ancestors)
        {
            var index      = property.Role.IndexOf(':');
            var entityName = index < 0 ? property.Role : property.Role.Substring(0, index);

            if (!property.Entity.Metadata.Manager.Entities.TryGet(entityName, out var entity))
            {
                throw new DataException($"The '{entityName}' target entity associated with the Role in the '{property.Entity.Name}:{property.Name}' complex property does not exist.");
            }

            if (index < 0)
            {
                return(entity.Properties);
            }

            var parts      = property.Role.Substring(index + 1).Split('.');
            var properties = entity.Properties;

            foreach (var part in parts)
            {
                if (properties == null)
                {
                    return(null);
                }

                if (!properties.TryGet(part, out var found))
                {
                    found = FindBaseProperty(ref properties, part, ref ancestors);

                    if (found == null)
                    {
                        throw new DataException($"The '{part}' property of '{properties.Entity.Name}' entity does not existed.");
                    }
                }

                if (found.IsSimplex)
                {
                    return(null);
                }

                properties = GetAssociatedProperties((IEntityComplexPropertyMetadata)found, ref ancestors);
            }

            return(properties);
        }
        /// <summary>
        /// 获取指定导航属性约束项值的常量表达式。
        /// </summary>
        /// <param name="property">指定的导航属性。</param>
        /// <param name="constraint">指定的导航属性的约束项。</param>
        /// <returns>返回的约束项值对应关联属性数据类型的常量表达式。</returns>
        public static ConstantExpression GetConstraintValue(this IEntityComplexPropertyMetadata property, AssociationConstraint constraint)
        {
            if (constraint.Value == null)
            {
                return(ConstantExpression.Null);
            }

            var entity = constraint.Actor == AssociationConstraintActor.Principal ? property.Entity : property.Foreign;

            //获取指定导航属性的关联属性
            if (!entity.Properties.TryGet(constraint.Name, out var associatedProperty))
            {
                throw new DataException($"The specified '{constraint.Name}' constraint does not exist in the '{property.Entity.Name}.{property.Name}' navigation property.");
            }

            //返回约束项值转换成关联属性数据类型的常量表达式
            return(Expression.Constant(Zongsoft.Common.Convert.ConvertValue(constraint.Value, Utility.FromDbType(associatedProperty.Type))));
        }