本文整理汇总了C#中ICriteria类的典型用法代码示例。如果您正苦于以下问题:C# ICriteria类的具体用法?C# ICriteria怎么用?C# ICriteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICriteria类属于命名空间,在下文中一共展示了ICriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
var sqlBuilder = new SqlStringBuilder();
SqlString[] columnNames = null;
if (_propertyName != "*")
{
columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);
if (columnNames.Length != 1)
{
throw new HibernateException("Contains may only be used with single-column properties");
}
} else
{
columnNames = new SqlString[]
{
new SqlString("*")
};
}
sqlBuilder.Add("contains(")
.Add(columnNames[0])
.Add(",");
sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());
sqlBuilder.Add(")");
return sqlBuilder.ToSqlString();
}
示例2: GetTypedValues
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new TypedValue[]
{
criteriaQuery.GetTypedValue(criteria, _propertyName, _value.ToString().ToLower())
};
}
示例3: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string entityName = criteriaQuery.GetEntityName(criteria, propertyName);
string actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName);
ISessionFactoryImplementor factory = criteriaQuery.Factory;
IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory);
string[] collectionKeys = collectionPersister.KeyColumnNames;
string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames;
StringBuilder innerSelect = new StringBuilder();
innerSelect.Append("(select 1 from ")
.Append(collectionPersister.TableName)
.Append(" where ")
.Append(
new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment());
if (collectionPersister.HasWhere)
{
innerSelect.Append(" and (")
.Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName))
.Append(") ");
}
innerSelect.Append(")");
return new SqlString(new string[] {ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString()});
}
示例4: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
IDictionary<string, IFilter> enabledFilters)
{
SqlString[] columnNames =
CriterionUtil.GetColumnNames(_lhsPropertyName, _lhsProjection, criteriaQuery, criteria, enabledFilters);
SqlString[] otherColumnNames =
CriterionUtil.GetColumnNames(_rhsPropertyName, _rhsProjection, criteriaQuery, criteria, enabledFilters);
SqlStringBuilder sb = new SqlStringBuilder();
if (columnNames.Length > 1)
{
sb.Add(StringHelper.OpenParen);
}
bool first = true;
foreach (SqlString sqlString in StringHelper.Add(columnNames, Op, otherColumnNames))
{
if (first == false)
{
sb.Add(" and ");
}
first = false;
sb.Add(sqlString);
}
if (columnNames.Length > 1)
{
sb.Add(StringHelper.ClosedParen);
}
return sb.ToSqlString();
}
示例5: GetProjectionArgument
private static SqlString GetProjectionArgument(ICriteriaQuery criteriaQuery, ICriteria criteria,
IProjection projection, int loc,
IDictionary<string, IFilter> enabledFilters)
{
SqlString sql = projection.ToSqlString(criteria, loc, criteriaQuery, enabledFilters);
return StringHelper.RemoveAsAliasesFromSql(sql);
}
示例6: GetTypes
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
IType[] trueTypes = whenTrue.GetTypes(criteria, criteriaQuery);
IType[] falseTypes = whenFalse.GetTypes(criteria, criteriaQuery);
bool areEqual = trueTypes.Length == falseTypes.Length;
if (trueTypes.Length == falseTypes.Length)
{
for (int i = 0; i < trueTypes.Length; i++)
{
if(trueTypes[i] != falseTypes[i])
{
areEqual = false;
break;
}
}
}
if(areEqual == false)
{
string msg = "Both true and false projections must return the same types."+ Environment.NewLine +
"But True projection returns: ["+StringHelper.Join(", ", trueTypes) +"] "+ Environment.NewLine+
"And False projection returns: ["+StringHelper.Join(", ", falseTypes)+ "]";
throw new HibernateException(msg);
}
return trueTypes;
}
示例7: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
//TODO: add default capacity
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
SqlString[] columnNames =
CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);
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();
}
示例8: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
if (_criteria.Count == 0)
{
return EmptyExpression;
}
//TODO: add default capacity
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
sqlBuilder.Add("(");
for (int i = 0; i < _criteria.Count - 1; i++)
{
sqlBuilder.Add(
((ICriterion) _criteria[i]).ToSqlString(criteria, criteriaQuery, enabledFilters));
sqlBuilder.Add(Op);
}
sqlBuilder.Add(
((ICriterion) _criteria[_criteria.Count - 1]).ToSqlString(criteria, criteriaQuery, enabledFilters));
sqlBuilder.Add(")");
return sqlBuilder.ToSqlString();
}
示例9: 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();
}
示例10: 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[] columns1 = GetColumnNames(criteria, criteriaQuery, this.propertyName);
string[] columns2 = null;
if (!(this.anotherGeometry is IGeometry))
{
columns2 = GetColumnNames(criteria, criteriaQuery, (string)this.anotherGeometry);
}
SqlStringBuilder builder = new SqlStringBuilder(10 * columns1.Length);
for (int i = 0; i < columns1.Length; i++)
{
if (i > 0)
{
builder.Add(" AND ");
}
if (this.anotherGeometry is IGeometry)
{
builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, Parameter.Placeholder, true));
}
else
{
builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, columns2[i], true));
}
}
return builder.ToSqlString();
}
示例11: FilterFacet
public FilterFacet(string name, ICriteria filter)
{
Argument.EnsureNotBlank("name", name);
this.name = name;
this.filter = filter;
}
示例12: GetTypedValues
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
if (projection != null)
return projection.GetTypedValues(criteria, criteriaQuery);
return base.GetTypedValues(criteria, criteriaQuery);
}
示例13: Join
protected Join(IDictionary<string, Join> joins, string toTable, string alias, ICriteria onCriteria)
: base(toTable, alias)
{
this.joins = joins;
this.onCriteria = onCriteria;
if (!ReferenceEquals(this.onCriteria, null))
{
var aliases = JoinAliasLocator.Locate(this.onCriteria.ToStringIgnoreParams());
if (aliases != null && aliases.Count > 0)
referencedAliases = aliases;
}
var toTableAliases = JoinAliasLocator.Locate(this.Table);
if (toTableAliases != null && toTableAliases.Count > 0)
{
if (referencedAliases == null)
referencedAliases = toTableAliases;
else
{
foreach (var x in toTableAliases)
referencedAliases.Add(x);
}
}
if (joins != null)
{
if (joins.ContainsKey(this.Name))
throw new ArgumentException(String.Format(
"There is already a join with alias '{0}'", this.Name));
joins.Add(this.Name, this);
}
}
示例14: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery,
IDictionary<string, IFilter> enabledFilters)
{
ISQLFunction sqlFunction = GetFunction(criteriaQuery);
List<string> tokens = new List<string>();
string replacemenToken = Guid.NewGuid().ToString("n");
for (int i = 0; i < args.Length; i++)
{
tokens.Add(replacemenToken);
}
string functionStatement = sqlFunction.Render(tokens, criteriaQuery.Factory).ToString();
string[] splitted = functionStatement.Split(new string[] {replacemenToken}, StringSplitOptions.RemoveEmptyEntries);
SqlStringBuilder sb = new SqlStringBuilder();
for (int i = 0; i < splitted.Length; i++)
{
sb.Add(splitted[i]);
if (i < args.Length)
{
int loc = (position + 1) * 1000 + i;
SqlString projectArg = GetProjectionArgument(criteriaQuery, criteria, args[i], loc, enabledFilters);
sb.Add(projectArg);
}
}
sb.Add(" as ");
sb.Add(GetColumnAliases(position)[0]);
return sb.ToSqlString();
}
示例15: GetRootCriteria
private static CriteriaImpl GetRootCriteria(ICriteria criteria)
{
CriteriaImpl impl = criteria as CriteriaImpl;
if (impl != null)
return impl;
return GetRootCriteria(((CriteriaImpl.Subcriteria)criteria).Parent);
}