/// <summary> /// Builds the select columns. /// </summary> /// <param name="reportColumns">The report columns.</param> /// <param name="context">The context.</param> /// <param name="settings">Conversion settings.</param> /// <returns>List{SelectColumn}.</returns> internal static List <SelectColumn> BuildSelectColumns(IEntityCollection <ReportColumn> reportColumns, FromEntityContext context, ReportToQueryConverterSettings settings) { List <SelectColumn> columns = new List <SelectColumn>(); // Order the columns based on position IEnumerable <ReportColumn> orderedReportColumns = reportColumns.OrderBy(rc => rc.ColumnDisplayOrder); foreach (ReportColumn orderedReportColumn in orderedReportColumns) { ScalarExpression scalarExpression = null; if (orderedReportColumn.ColumnExpression == null) { context.ReportInvalidColumns[orderedReportColumn.Id] = orderedReportColumn.Name; if (!settings.SchemaOnly) { continue; } } else { scalarExpression = BuildExpression(orderedReportColumn.ColumnExpression, context); if (scalarExpression == null) { EventLog.Application.WriteWarning("the column expression id: {0} is invalid.", orderedReportColumn.ColumnExpression.Id.ToString()); context.ReportInvalidColumns[orderedReportColumn.Id] = orderedReportColumn.Name; if (!settings.SchemaOnly) { continue; } } } Guid columnId = Guid.NewGuid(); SelectColumn selectColumn = new SelectColumn { IsHidden = orderedReportColumn.ColumnIsHidden ?? false, DisplayName = orderedReportColumn.Name, Expression = scalarExpression, ColumnId = columnId, EntityId = orderedReportColumn.Id }; context.ReportColumnMap[orderedReportColumn.Id] = columnId; columns.Add(selectColumn); } return(columns); }
/// <summary> /// Builds the order by collection. /// </summary> /// <param name="reportOrderBys">The report order bys.</param> /// <param name="context">The context.</param> /// <param name="settings">Conversion settings.</param> /// <returns>List{OrderByItem}.</returns> internal static List <OrderByItem> BuildOrderBy(IEntityCollection <ReportOrderBy> reportOrderBys, FromEntityContext context, ReportToQueryConverterSettings settings) { List <OrderByItem> orderByItems = new List <OrderByItem>(); if (context.Settings.ConditionsOnly) { return(orderByItems); // don't bother converting them (e.g. for use in security) } foreach (ReportOrderBy reportOrderBy in reportOrderBys.OrderBy(rob => rob.OrderPriority)) { ScalarExpression expression = BuildExpression(reportOrderBy.OrderByExpression, context); if (expression == null) { EventLog.Application.WriteWarning("the order expression id: {0} is invalid.", reportOrderBy.OrderByExpression != null ? reportOrderBy.OrderByExpression.Id.ToString() : "null"); continue; } //the orderby expression is ColumnReferenceExpression, the referenced report column must exists if (context.ColumnReferenceMap.ContainsKey(expression.ExpressionId) && context.ReportColumnMap.ContainsKey(context.ColumnReferenceMap[expression.ExpressionId])) { OrderByItem orderByItem = new OrderByItem { Direction = reportOrderBy.ReverseOrder ?? false ? OrderByDirection.Descending : OrderByDirection.Ascending, Expression = expression }; orderByItems.Add(orderByItem); } } return(orderByItems); }