public DataAssociationLink(IDataEntityComplexProperty owner, string name, string role) { _owner = owner; _name = name; _role = role; _principal = _foreign = null; }
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; }
private static IDataEntityPropertyCollection GetAssociatedProperties(IDataEntityComplexProperty property, ref ICollection <IDataEntity> 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((IDataEntityComplexProperty)found, ref ancestors); } return(properties); }
/// <inheritdoc /> public JoinClause Join(Aliaser aliaser, ISource source, IDataEntityComplexProperty complex, string fullPath = null) { var joins = JoinClause.Create(source, complex, fullPath, name => this.From.TryGet(name, out var join) ? (JoinClause)join : null, entity => new TableIdentifier(entity, aliaser.Generate())); JoinClause last = null; foreach (var join in joins) { if (!this.From.Contains(join)) { this.From.Add(join); } last = join; } //返回最后一个Join子句 return(last); }
/// <summary> /// 获取指定导航属性约束项值的常量表达式。 /// </summary> /// <param name="property">指定的导航属性。</param> /// <param name="constraint">指定的导航属性的约束项。</param> /// <returns>返回的约束项值对应关联属性数据类型的常量表达式。</returns> public static ConstantExpression GetConstraintValue(this IDataEntityComplexProperty property, DataAssociationConstraint constraint) { if (constraint.Value == null) { return(ConstantExpression.Null); } var entity = constraint.Actor == DataAssociationConstraintActor.Principal ? property.Entity : property.Foreign; //获取指定导航属性的关联属性 if (!entity.Properties.TryGet(constraint.Name, out var constraintProperty)) { throw new DataException($"The specified '{constraint.Name}' constraint does not exist in the '{property.Entity.Name}.{property.Name}' navigation property."); } //如果约束项的关联属性不是简单属性则抛出异常 if (!constraintProperty.IsSimplex) { throw new DataException($"The specified '{constraint.Name}' constraint association property is not a simplex property."); } //返回约束项值转换成关联属性数据类型的常量表达式 return(Expression.Constant(Zongsoft.Common.Convert.ConvertValue(constraint.Value, Utility.FromDbType(((IDataEntitySimplexProperty)constraintProperty).Type)))); }
/// <summary> /// 获取指定导航属性是否有约束定义。 /// </summary> /// <param name="property">指定的导航属性。</param> /// <returns>如果指定的导航属性定义了约束则返回真(True),否则返回假(False)。</returns> public static bool HasConstraints(this IDataEntityComplexProperty property) { return(property != null && property.Constraints != null && property.Constraints.Length > 0); }