forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLCriterion.cs
49 lines (44 loc) · 1.31 KB
/
SQLCriterion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Expression
{
/// <summary>
/// An <see cref="ICriterion"/> that creates a SQLExpression.
/// The string {alias} will be replaced by the alias of the root entity.
/// </summary>
/// <remarks>
/// This allows for database specific Expressions at the cost of needing to
/// write a correct <see cref="SqlString"/>.
/// </remarks>
[Serializable]
public class SQLCriterion : AbstractCriterion
{
private readonly SqlString _sql;
private readonly TypedValue[] _typedValues;
public SQLCriterion(SqlString sql, object[] values, IType[] types)
{
_sql = sql;
_typedValues = new TypedValue[values.Length];
for (int i = 0; i < _typedValues.Length; i++)
{
_typedValues[i] = new TypedValue(types[i], values[i]);
}
}
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria));
}
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return _typedValues;
}
/// <summary></summary>
public override string ToString()
{
return _sql.ToString();
}
}
}