/// <summary> /// Gets the sort specification for this attribute. /// </summary> /// <returns></returns> public SortSpecificationCollection GetSortSpecification(EntityType entityType) { if (entityType == null) { throw new ArgumentNullException("entityType"); } if (FieldNames == null) { throw new ArgumentNullException("FieldNames"); } if (Directions == null) { throw new ArgumentNullException("Directions"); } if (FieldNames.Length != Directions.Length) { throw ExceptionHelper.CreateLengthMismatchException("FieldNames", "Directions", FieldNames.Length, Directions.Length); } // create... SortSpecificationCollection specifications = new SortSpecificationCollection(); for (int index = 0; index < this.FieldNames.Length; index++) { string fieldName = FieldNames[index]; // get and add... EntityField field = entityType.Fields.GetField(fieldName, OnNotFound.ThrowException); specifications.Add(new SortSpecification(field, this.Directions[index])); } // return... return(specifications); }
/// <summary> /// Constructor. /// </summary> protected SqlStatementCreator(EntityType entityType, EntityField[] fields) { if (entityType == null) { throw new ArgumentNullException("entityType"); } if (fields == null) { throw new ArgumentNullException("fields"); } // set... _entityType = entityType; // mjr - 12-10-2005 - setup the dialect... if (entityType.HasDatabaseName) { // mjr - 12-10-2005 - this needs to be refactored (not ideal)... using (IConnection connection = Database.CreateConnection(entityType.DatabaseName)) this.Dialect = connection.Dialect; } else { Dialect = Database.DefaultDialect; } // set... if (Dialect == null) { throw new InvalidOperationException("Dialect is null."); } // do the fields... _fields = new EntityFieldCollection(entityType); // mbr - 16-10-2005 - now done on demand... // if(fields.Length == 0) // { // // get default fields... // fields = entityType.GetCommonFields(); // if(fields.Length == 0) // { // fields = entityType.GetKeyFields(); // if(fields.Length == 0) // throw new InvalidOperationException(string.Format("Entity type '{0}' has no common fields and no key fields.", entityType)); // } // } // add the ones passed into the constructor... _fields.AddRange(fields); // order... _sortOrder = entityType.DefaultSortOrder.Clone(); this.FirstApplySortCall = true; this.ArrayParameterType = Database.ArrayParameterType; }