public static ISource From(this IStatement statement, TableIdentifier origin, string memberPath, Func <ISource, IDataEntityComplexProperty, ISource> subqueryFactory, out IDataEntityProperty property) { var found = origin.Reduce(memberPath, ctx => { var source = ctx.Source; if (ctx.Ancestors != null) { foreach (var ancestor in ctx.Ancestors) { source = statement.Join(source, ancestor, ctx.Path); } } if (ctx.Property.IsComplex) { var complex = (IDataEntityComplexProperty)ctx.Property; if (complex.Multiplicity == DataAssociationMultiplicity.Many) { if (subqueryFactory != null) { return(subqueryFactory(source, complex)); } //如果不允许一对多的子查询则抛出异常 throw new DataException($"The specified '{ctx.FullPath}' member is a one-to-many composite(navigation) property that cannot appear in the sorting and specific condition clauses."); } source = statement.Join(source, complex, ctx.FullPath); } return(source); }); if (found.IsFailed) { throw new DataException($"The specified '{memberPath}' member does not exist in the '{origin.Entity?.Name}' entity and it's inherits."); } //输出找到的属性元素 property = found.Property; //返回找到的源 return(found.Source); }