public void BuildQuery() { if (ConsultQuery.Length != 0) { ConsultQuery.Clear(); } //Setup Top if (Top != null && Top != 0) { ConsultQuery.AppendLine("select top ").Append(Top.Value.ToString()).Append(" ").Append(Fields.ToString()).Append(Entities.ToString()).Append(Where.ToString()); } else { ConsultQuery.AppendLine("select ").Append(Fields.ToString()).Append(Entities.ToString()).Append(Where.ToString()); } if (EnableGroupBy) { ConsultQuery.AppendFormat("group by {0}", FieldsWithoutAlias.ToString()); } //Setup OrderBy if (OrderBy.Length != 0) { ConsultQuery.Append(" order by ").AppendLine(string.Join(", ", OrderBy)); } //Setup Pagination if (Paginate.Enabled) { StringBuilder TotalRowsCount = new StringBuilder(); if (EnableGroupBy) { TotalRowsCount.Append("set @totalRows = (select count(*) from (select 1 as [1] ") .Append(Entities.ToString()) .Append(Where.ToString()) .AppendFormat("group by {0}", FieldsWithoutAlias.ToString()) .Append(") as tbCC)").AppendLine().AppendLine(); } else { TotalRowsCount.Append("set @totalRows = (select count(*) ").Append(Entities.ToString()).Append(Where.ToString()).Append(")").AppendLine().AppendLine(); } ConsultQuery.Insert(0, TotalRowsCount).AppendLine(" OFFSET ((@PageNumber - 1) * @RowspPage) ROWS").AppendLine(" FETCH NEXT @RowspPage ROWS ONLY"); } }
public int AddCustomField(string Query) { if (Fields.Length != 0) { Fields.Append(","); FieldsWithoutAlias.Append(","); } if (EntityCount >= 1) { Fields.Append(string.Concat(" ", Query, " as [", ++FieldCount, "]")).AppendLine(); } else { return(0); } FieldsWithoutAlias.Append(string.Concat(" ", Query)).AppendLine(); return(FieldCount - 1); //IMPORTANTE Retorna -1 porque o GetData busca os campos por indice e não por nome. }
public int AddField(string pEntity, string pAttribute) { if (Fields.Length != 0) { Fields.Append(","); FieldsWithoutAlias.Append(","); } if (EntityCount >= 1) { Fields.Append(string.Concat(" [", pEntity, "].[", pAttribute, "] as [", ++FieldCount, "]")).AppendLine(); } else { return(0); } FieldsWithoutAlias.Append(string.Concat(" [", pEntity, "].[", pAttribute, "]")).AppendLine(); return(FieldCount - 1); //IMPORTANTE Retorna -1 porque o GetData busca os campos por indice e não por nome. }