forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountProjection.cs
51 lines (45 loc) · 1.08 KB
/
CountProjection.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
50
51
using System;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Expression
{
/// <summary>
/// A Count
/// </summary>
[Serializable]
public class CountProjection : AggregateProjection
{
private bool distinct;
protected internal CountProjection(String prop)
: base("count", prop)
{
}
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new IType[] {NHibernateUtil.Int32};
}
public override string ToString()
{
return (distinct) ? "distinct " + base.ToString() : base.ToString();
}
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
{
SqlStringBuilder buf = new SqlStringBuilder()
.Add("count(");
if (distinct)
{
buf.Add("distinct ");
}
buf.Add(criteriaQuery.GetColumn(criteria, propertyName))
.Add(") as y")
.Add(position.ToString())
.Add("_");
return buf.ToSqlString();
}
public CountProjection SetDistinct()
{
distinct = true;
return this;
}
}
}