public static void Render <T>(IEnumerable <ResultOrderingModel> orderBy, StringBuilder sb) { var olist = orderBy?.ToList(); if ((olist == null) || (olist.Count == 0)) { return; } sb.Append(" ORDER BY "); for (var i = 0; i < olist.Count; i++) { if (i > 0) { sb.Append(", "); } var order = olist[i]; var propchain = ExpressionsHelper.GetPropertiesChainText <T>(ExpressionsHelper.RemoveConvert(order.Expression)); if (string.IsNullOrWhiteSpace(propchain)) { throw new InvalidOperationException($"Invalid OrderBy expression {order.Expression}"); } var tabAndCol = DotPathHelper.SplitToEntityAndAttribute(propchain); sb.Append($"[{tabAndCol.Item1}].[{tabAndCol.Item2}]"); sb.Append(order.Ascending ? " ASC" : " DESC"); } sb.AppendLine(); }
private void VisitEntity(Type entityType, string path, List <SelectedColumnModel> columns, List <JoinModel> joins) { foreach (var datacolumn in m_dataModel.GetTableDataColumns(entityType)) { columns.Add(new SelectedColumnModel(path, m_dataModel.GetColumnName(datacolumn), null)); } foreach (var reference in m_dataModel.GetReferences(entityType)) { var propertyPath = $"{path}.{reference.LeftModelPropertyName}"; if (!IsIncluded(propertyPath)) { continue; } var joinedTableAlias = DotPathHelper.Combine(path, reference.LeftModelPropertyName); var join = new JoinModel() { JoinType = JoinType.Left, Condition = $"[{path}].[{reference.LeftKeyColumnName}]=[{joinedTableAlias}].[{reference.RightKeyColumnName}]", JoinedTableAlias = joinedTableAlias, JoinedTableName = m_dataModel.GetTableName(reference.RightEntityType) }; joins.Add(join); VisitEntity(reference.RightEntityType, joinedTableAlias, columns, joins); } }
private void Include(string propertyPath) { propertyPath = DotPathHelper.TrimDots(propertyPath); while (propertyPath.Contains(".")) { m_inclusions.Add(propertyPath); propertyPath = DotPathHelper.GetParent(propertyPath); } }
protected override IQuerySegment MapMemberExpression(MemberExpression expression) { var propChain = ExpressionsHelper.GetPropertiesChainText <T>(expression); if (string.IsNullOrWhiteSpace(propChain)) { throw new NotSupportedException($"Unsupported expression {expression}"); } var tableAndColumn = DotPathHelper.SplitToEntityAndAttribute(propChain); var tableAlias = tableAndColumn.Item1; var column = tableAndColumn.Item2; return(new ColumnSegment(tableAlias, column)); }
private bool IsIncluded(string propertyPath) { propertyPath = DotPathHelper.TrimDots(propertyPath); return(m_inclusions.Contains(propertyPath)); }
public void TestGetParent(string inp, string exp) { Assert.Equal(exp, DotPathHelper.GetParent(inp)); }
public void TestCombine(string a, string b, string exp) { Assert.Equal(exp, DotPathHelper.Combine(a, b)); }
public void TestTrimDots(string inp, string exp) { Assert.Equal(exp, DotPathHelper.TrimDots(inp)); }