forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexedCollection.cs
75 lines (65 loc) · 1.48 KB
/
IndexedCollection.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
using System;
using NHibernate.Engine;
namespace NHibernate.Mapping
{
/// <summary>
/// Indexed collections include IList, IDictionary, Arrays
/// and primitive Arrays.
/// </summary>
[Serializable]
public abstract class IndexedCollection : Collection
{
public const string DefaultIndexColumnName = "idx";
private SimpleValue index;
protected IndexedCollection(PersistentClass owner) : base(owner)
{
}
public SimpleValue Index
{
get { return index; }
set { index = value; }
}
public override bool IsIndexed
{
get { return true; }
}
public virtual bool IsList
{
get { return false; }
}
public override void CreatePrimaryKey()
{
if (!IsOneToMany)
{
PrimaryKey pk = new PrimaryKey();
pk.AddColumns(Key.ColumnIterator);
// index should be last column listed
bool isFormula = false;
foreach (ISelectable selectable in Index.ColumnIterator)
{
if(selectable.IsFormula)
isFormula = true;
}
if (isFormula)
{
//if it is a formula index, use the element columns in the PK
pk.AddColumns(Element.ColumnIterator);
}
else
{
pk.AddColumns(Index.ColumnIterator);
}
CollectionTable.PrimaryKey = pk;
}
}
public override void Validate(IMapping mapping)
{
base.Validate(mapping);
if (!Index.IsValid(mapping))
{
throw new MappingException(
string.Format("collection index mapping has wrong number of columns: {0} type: {1}", Role, Index.Type.Name));
}
}
}
}