private string GetPropertyChainColumn(string chain, ORMSelect q) { EnsureChainJoins(chain, q); List <PropertyInfo> pis = new ORMPropertyChain(chain).GetChain(q.FocalType); PropertyInfo endProp = pis[pis.Count - 1]; SchemaTable t = _Schema.EnsureSchema(endProp.ReflectedType); string colName = t.GetColumnByName(endProp.Name).Column.Name; return(GetJoinAlias(chain, q) + "." + colName); }
public ORMSelectQueryBuilder(ORMSelect select, SchemaManager schema) { _Schema = schema; SQSelectQuery q = new SQSelectQuery(); _Query = q; SchemaTable t = _Schema.EnsureSchema(select.FocalType); q.From = new SQFromClause(); q.From.Tables.Add(new SQFromTable(t.Table.Name, select.FocalType.Name)); if (select.Columns.Count == 0) { foreach (SQColumn col in t.Table.Columns) { q.Columns.Add(new SQAliasableObject(select.FocalType.Name + "." + col.Name)); } } else { foreach (string col in select.Columns) { EnsureChainJoins(col, select); q.Columns.Add(new SQAliasableObject(GetPropertyChainColumn(col, select))); } } q.Condition = GetCondition(select.Condition, select); q.Top = select.Top; if (select.SortProperties != null) { foreach (ORMSortProperty sp in select.SortProperties) { EnsureChainJoins(sp.Property, select); q.SortColumns.Add(new SQSortColumn() { Column = GetPropertyChainColumn(sp.Property, select), Direction = !sp.Ascending.HasValue ? SortOrder.Unspecified : sp.Ascending.Value ? SortOrder.Ascending : SortOrder.Descending }); } } q.RecordCount = select.RecordCount; q.RecordStart = select.RecordStart; }