/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { IEnumerable <Parameter> parameters = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)); Parameter p = null; foreach (Parameter p_ in parameters) { p = p_; } //Parameter[] p = criteriaQuery.NewQueryParameter(GetTypedValues(criteria, criteriaQuery)[0]).ToArray(); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } string[] keyColumns = criteriaQuery.GetIdentifierColumns(criteria); string entityType = criteriaQuery.GetEntityName(criteria, this.propertyName); AbstractEntityPersister entityPersister = (AbstractEntityPersister)criteriaQuery.Factory.GetEntityPersister(entityType); // Only one key column is assumed string keyColumn = keyColumns[0]; string alias = criteriaQuery.GetSQLAlias(criteria, this.propertyName); string tableName = entityPersister.TableName; int aliasLength = alias.Length + 1; SqlStringBuilder builder = new SqlStringBuilder(10 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } string geometryColumn = columnsUsingProjection[i].Remove(0, aliasLength); builder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName, p)); } return(builder.ToSqlString()); }
public SqlString GetSpatialFilterString(string tableAlias, string geometryColumnName, string primaryKeyColumnName, string tableName, Parameter parameter) { return(worker.GetSpatialFilterString(tableAlias, geometryColumnName, primaryKeyColumnName, tableName, parameter)); }