public FieldSorting this[string fieldNameOrAlias] { get { if (String.IsNullOrEmpty(fieldNameOrAlias)) throw new ArgumentNullException("fieldNameOrAlias"); TableField field = this.View.Fields.SingleOrDefault(f => f.Alias == fieldNameOrAlias || f.Name == fieldNameOrAlias); if (null == field) throw new ArgumentException(String.Format("View '{0}' doesn't have a field '{1}'", this.View.Name, fieldNameOrAlias)); FieldSorting sortedField = this.SortedFields.SingleOrDefault(sf => sf.Field == field); if (null == sortedField) { sortedField = new FieldSorting(field); this.SortedFields.Add(sortedField); } return sortedField; } }
public FieldSorting this[string fieldNameOrAlias] { get { if (String.IsNullOrEmpty(fieldNameOrAlias)) { throw new ArgumentNullException("fieldNameOrAlias"); } TableField field = this.View.Fields.SingleOrDefault(f => f.Alias == fieldNameOrAlias || f.Name == fieldNameOrAlias); if (null == field) { throw new ArgumentException(String.Format("View '{0}' doesn't have a field '{1}'", this.View.Name, fieldNameOrAlias)); } FieldSorting sortedField = this.SortedFields.SingleOrDefault(sf => sf.Field == field); if (null == sortedField) { sortedField = new FieldSorting(field); this.SortedFields.Add(sortedField); } return(sortedField); } }
public void CompileSql(StringBuilder builder, bool isFilterSubview) { if (null == builder) { throw new ArgumentNullException("builder"); } SetUpTokens(!isFilterSubview); // cmd if (!isFilterSubview) { builder.AppendLine("exec sp_executesql N'"); } builder.AppendLine("select " + (this.Distinct ? "distinct" : "")); this.Fields.ToSql(builder, this.Aliases); if (this.ComputedFields.Count > 0) { builder.AppendLine(","); } this.ComputedFields.ToSql(builder, this.Aliases); builder.AppendLine(); builder.AppendLine("from"); builder.Append(" "); builder.AppendFormat("[{0}]", this.Source.Name); builder.AppendLine(); if (this.Relationship.Count > 0) { this.Relationship.ToSql(builder, this.Source); } if (this.Filters.Count > 0) { builder.AppendLine(); builder.AppendLine("where"); this.Filters.ToSql(builder); } for (int i = 0; i < this.Sorting.SortedFields.Count; i++) { FieldSorting sorting = this.Sorting.SortedFields[i]; string op = null; if (sorting.Direction == SortingOptions.Up) { op = "asc"; } else if (sorting.Direction == SortingOptions.Down) { op = "desc"; } if (String.IsNullOrEmpty(op)) { continue; } if (i == 0) { builder.AppendLine(); builder.Append("order by "); } else { builder.AppendLine(", "); } builder.AppendFormat("[{0}].[{1}] {2}", sorting.Field.Table.Name, sorting.Field.Name, op); } if (!isFilterSubview) { builder.Append("'"); } if (!this.Parameters.IsEmpty && !isFilterSubview) { builder.AppendLine(","); // parameters declaration builder.Append("N'"); bool firstParameter = true; foreach (string parameter in this.Parameters) { if (!String.IsNullOrEmpty(parameter)) // can be empty if this is a subview and this parameter is linked with a field of the superview { string identifier = this.Parameters.SqlIdentifier(parameter); if (!firstParameter) { builder.Append(", "); } else { firstParameter = false; } builder.AppendFormat("{0} varchar(max)", identifier); } } builder.AppendLine("',"); } }