forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertyProjection.cs
78 lines (68 loc) · 1.75 KB
/
PropertyProjection.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
73
74
75
76
77
78
using System;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Criterion
{
/// <summary>
/// A property value, or grouped property value
/// </summary>
[Serializable]
public class PropertyProjection : SimpleProjection, IPropertyProjection
{
private string propertyName;
private bool grouped;
protected internal PropertyProjection(string propertyName, bool grouped)
{
this.propertyName = propertyName;
this.grouped = grouped;
}
protected internal PropertyProjection(string propertyName)
: this(propertyName, false)
{
}
public string PropertyName
{
get { return propertyName; }
}
public override string ToString()
{
return propertyName;
}
public override bool IsGrouped
{
get { return grouped; }
}
public override bool IsAggregate
{
get { return false; }
}
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new IType[] {criteriaQuery.GetType(criteria, propertyName)};
}
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery)
{
SqlStringBuilder s = new SqlStringBuilder();
string[] cols = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
for (int i = 0; i < cols.Length; i++)
{
s.Add(cols[i]);
s.Add(" as y");
s.Add((loc + i).ToString());
s.Add("_");
if (i < cols.Length - 1)
s.Add(", ");
}
return s.ToSqlString();
}
public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
if (!grouped)
{
throw new InvalidOperationException("not a grouping projection");
}
return new SqlString(string.Join(",", criteriaQuery.GetColumns(criteria, propertyName)));
}
}
}