本文整理汇总了C#中ICriteriaQuery.GetColumnsUsingProjection方法的典型用法代码示例。如果您正苦于以下问题:C# ICriteriaQuery.GetColumnsUsingProjection方法的具体用法?C# ICriteriaQuery.GetColumnsUsingProjection怎么用?C# ICriteriaQuery.GetColumnsUsingProjection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICriteriaQuery
的用法示例。
在下文中一共展示了ICriteriaQuery.GetColumnsUsingProjection方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetColumnNamesUsingPropertyName
private static SqlString[] GetColumnNamesUsingPropertyName(
ICriteriaQuery criteriaQuery,
ICriteria criteria,
string propertyName,
object value,
ICriterion critertion)
{
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
IType propertyType = criteriaQuery.GetTypeUsingProjection(criteria, propertyName);
if (value != null && !(value is System.Type) && !propertyType.ReturnedClass.IsInstanceOfType(value))
{
throw new QueryException(string.Format(
"Type mismatch in {0}: {1} expected type {2}, actual type {3}",
critertion.GetType(), propertyName, propertyType.ReturnedClass, value.GetType()));
}
if (propertyType.IsCollectionType)
{
throw new QueryException(string.Format(
"cannot use collection property ({0}.{1}) directly in a criterion,"
+ " use ICriteria.CreateCriteria instead",
criteriaQuery.GetEntityName(criteria), propertyName));
}
return Array.ConvertAll<string, SqlString>(columnNames, delegate(string col)
{
return new SqlString(col);
});
}
示例2: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
{
//TODO: add default capacity
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);
bool opNeeded = false;
for (int i = 0; i < columnNames.Length; i++)
{
if (opNeeded)
{
sqlBuilder.Add(" or ");
}
opNeeded = true;
sqlBuilder.Add(columnNames[i])
.Add(" is not null");
}
if (columnNames.Length > 1)
{
sqlBuilder.Insert(0, "(");
sqlBuilder.Add(")");
}
return sqlBuilder.ToSqlString();
}
示例3: ToSqlString
/// <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)
{
criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect;
string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName);
IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName);
if (typeUsingProjection.ReturnedClass != typeof(IGeometry))
{
throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", GetType(), this.propertyName, typeof(IGeometry), typeUsingProjection.ReturnedClass));
}
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));
}
SqlStringBuilder builder = new SqlStringBuilder(2 * columnsUsingProjection.Length);
for (int i = 0; i < columnsUsingProjection.Length; i++)
{
if (i > 0)
{
builder.Add(" AND ");
}
builder.Add(spatialDialect.GetSpatialValidationString(columnsUsingProjection[i], this.validation, true));
}
return builder.ToSqlString();
}
示例4: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
{
//TODO: add default capacity
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);
if (columnNames.Length != 1)
{
throw new HibernateException("insensitive like may only be used with single-column properties");
}
if (criteriaQuery.Factory.Dialect is PostgreSQLDialect)
{
sqlBuilder.Add(columnNames[0]);
sqlBuilder.Add(" ilike ");
}
else
{
sqlBuilder.Add(criteriaQuery.Factory.Dialect.LowercaseFunction)
.Add("(")
.Add(columnNames[0])
.Add(")")
.Add(" like ");
}
sqlBuilder.AddParameter();
return sqlBuilder.ToSqlString();
}
示例5: ToSqlString
/// <summary>
/// Converts the SimpleExpression to a <see cref="SqlString"/>.
/// </summary>
/// <returns>A SqlString that contains a valid Sql fragment.</returns>
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
{
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);
IType propertyType = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName);
if (_value != null && !(_value is System.Type) && !propertyType.ReturnedClass.IsInstanceOfType(_value))
{
throw new QueryException(string.Format(
"Type mismatch in {0}: {1} expected type {2}, actual type {3}",
GetType(), _propertyName, propertyType.ReturnedClass, _value.GetType()));
}
if (propertyType.IsCollectionType)
{
throw new QueryException(string.Format(
"cannot use collection property ({0}.{1}) directly in a criterion,"
+ " use ICriteria.CreateCriteria instead",
criteriaQuery.GetEntityName(criteria), _propertyName));
}
if (_ignoreCase)
{
if (columnNames.Length != 1)
{
throw new HibernateException(
"case insensitive expression may only be applied to single-column properties: " +
_propertyName);
}
return new SqlStringBuilder(6)
.Add(criteriaQuery.Factory.Dialect.LowercaseFunction)
.Add(StringHelper.OpenParen)
.Add(columnNames[0])
.Add(StringHelper.ClosedParen)
.Add(Op)
.AddParameter()
.ToSqlString();
}
else
{
//TODO: add default capacity
SqlStringBuilder sqlBuilder = new SqlStringBuilder(4 * columnNames.Length);
for (int i = 0; i < columnNames.Length; i++)
{
if (i > 0)
{
sqlBuilder.Add(" and ");
}
sqlBuilder.Add(columnNames[i])
.Add(Op)
.AddParameter();
}
return sqlBuilder.ToSqlString();
}
}
示例6: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
{
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _lhsPropertyName);
string[] otherColumnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _rhsPropertyName);
string result = string.Join(
" and ",
StringHelper.Add(columnNames, Op, otherColumnNames)
);
if (columnNames.Length > 1)
{
result = StringHelper.OpenParen + result + StringHelper.ClosedParen;
}
return new SqlString(result);
//TODO: get SQL rendering out of this package!
}
示例7: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
return new SqlStringBuilder()
.Add("(")
.Add(projection[0])
.Add(" + ")
.AddParameter()
.Add(") as ")
.Add(GetColumnAliases(0)[0])
.ToSqlString();
}
示例8: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
SqlStringBuilder s = new SqlStringBuilder();
string[] cols = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
for (int i = 0; i < cols.Length; i++)
{
s.Add(cols[i]);
s.Add(" as y");
s.Add((loc + i).ToString());
s.Add("_");
if (i < cols.Length - 1)
s.Add(", ");
}
return s.ToSqlString();
}
示例9: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
{
IType type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName);
if (type.IsCollectionType)
{
throw new QueryException("Cannot use collections with InExpression");
}
if (_values.Length == 0)
{
// "something in ()" is always false
return new SqlString("1=0");
}
//TODO: add default capacity
SqlStringBuilder result = new SqlStringBuilder();
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);
// Generate SqlString of the form:
// columnName1 in (values) and columnName2 in (values) and ...
for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
{
string columnName = columnNames[columnIndex];
if (columnIndex > 0)
{
result.Add(" and ");
}
result
.Add(columnName)
.Add(" in (");
for (int i = 0; i < _values.Length; i++)
{
if (i > 0)
{
result.Add(StringHelper.CommaSpace);
}
result.AddParameter();
}
result.Add(")");
}
return result.ToSqlString();
}
示例10: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string[] columns = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
if (columns.Length != 1)
throw new HibernateException("Like may only be used with single-column properties");
SqlStringBuilder lhs = new SqlStringBuilder(6);
if(ignoreCase)
{
Dialect.Dialect dialect = criteriaQuery.Factory.Dialect;
lhs.Add(dialect.LowercaseFunction).Add(StringHelper.OpenParen).Add(columns[0]).Add(
StringHelper.ClosedParen);
}
else
lhs.Add(columns[0]);
lhs.Add(" like ").AddParameter();
if (escapeChar.HasValue)
lhs.Add(" escape '" + escapeChar + "'");
return lhs.ToSqlString();
}
示例11: ToSqlString
/// <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)
{
//criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
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));
}
return builder.ToSqlString();
}
示例12: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string,IFilter> enabledFilters)
{
//we only need this for SQL Server, and or large amount of values
if ((criteriaQuery.Factory.Dialect is MsSql2005Dialect) == false || values.Length < maximumNumberOfParametersToNotUseXml)
{
return expr.ToSqlString(criteria, criteriaQuery, enabledFilters);
}
IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName);
if (type.IsCollectionType)
{
throw new QueryException("Cannot use collections with InExpression");
}
if (values.Length == 0)
{
// "something in ()" is always false
return new SqlString("1=0");
}
SqlStringBuilder result = new SqlStringBuilder();
string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
// Generate SqlString of the form:
// columnName1 in (xml query) and columnName2 in (xml query) and ...
criteriaQuery.AddUsedTypedValues(this.GetTypedValues(criteria, criteriaQuery));
for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
{
string columnName = columnNames[columnIndex];
if (columnIndex > 0)
{
result.Add(" and ");
}
SqlType sqlType = type.SqlTypes(criteriaQuery.Factory)[columnIndex];
result
.Add(columnName)
.Add(" in (")
.Add("SELECT ParamValues.Val.value('.','")
.Add(criteriaQuery.Factory.Dialect.GetTypeName(sqlType))
.Add("') FROM ")
.AddParameter()
.Add(".nodes('/items/val') as ParamValues(Val)")
.Add(")");
}
return result.ToSqlString();
}
示例13: GetColumnNames
/// <summary>
/// Gets the column names.
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <param name="criteriaQuery">The criteria query.</param>
/// <param name="propertyName">Name of the property.</param>
/// <returns></returns>
private string[] GetColumnNames(ICriteria criteria, ICriteriaQuery criteriaQuery, string propertyName)
{
string[] columns = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName);
if (type.ReturnedClass != typeof(IGeometry))
{
throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", base.GetType(), propertyName, typeof(IGeometry), type.ReturnedClass));
}
if (type.IsCollectionType)
{
throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), propertyName));
}
return columns;
}