forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentifierProjection.cs
72 lines (61 loc) · 1.55 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
64
65
66
67
68
69
70
71
72
using System;
using NHibernate.Persister.Entity;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Criterion
{
[Serializable]
public class IdentifierProjection : SimpleProjection, IPropertyProjection
{
private bool grouped;
protected internal IdentifierProjection(bool grouped)
{
this.grouped = grouped;
}
protected internal IdentifierProjection() : this(false)
{
}
public override string ToString()
{
return PropertyName;
}
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 bool IsAggregate
{
get { return false; }
}
public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
if (!grouped)
{
throw new InvalidOperationException("not a grouping projection");
}
return new SqlString(string.Join(",", criteriaQuery.GetIdentifierColumns(criteria)));
}
public string PropertyName => EntityPersister.EntityID;
}
}