forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentifierProjection.cs
63 lines (54 loc) · 1.43 KB
/
IdentifierProjection.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
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Expression
{
[Serializable]
public class IdentifierProjection : SimpleProjection
{
private bool grouped;
protected internal IdentifierProjection(bool grouped)
{
this.grouped = grouped;
}
protected internal IdentifierProjection() : this(false)
{
}
public override string ToString()
{
return "id";
}
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new IType[] {criteriaQuery.GetIdentifierType(criteria)};
}
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
{
SqlStringBuilder buf = new SqlStringBuilder();
string[] cols = criteriaQuery.GetIdentifierColumns(criteria);
for (int i = 0; i < cols.Length; i++)
{
if (i > 0)
{
buf.Add(", ");
}
buf.Add(cols[i])
.Add(" as y")
.Add((position + i).ToString())
.Add("_");
}
return buf.ToSqlString();
}
public override bool IsGrouped
{
get { return grouped; }
}
public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return (grouped) ?
new SqlString(StringHelper.Join(",", criteriaQuery.GetIdentifierColumns(criteria)))
: base.ToGroupSqlString(criteria, criteriaQuery);
}
}
}