forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentifierCollection.cs
62 lines (56 loc) · 1.31 KB
/
IdentifierCollection.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
using System;
using NHibernate.Engine;
namespace NHibernate.Mapping
{
/// <summary>
/// A collection with a synthetic "identifier" column.
/// </summary>
[Serializable]
public abstract class IdentifierCollection : Collection
{
public const string DefaultIdentifierColumnName = "id";
private IKeyValue identifier;
/// <summary>
///
/// </summary>
/// <param name="owner"></param>
protected IdentifierCollection(PersistentClass owner) : base(owner)
{
}
/// <summary></summary>
public IKeyValue Identifier
{
get { return identifier; }
set { identifier = value; }
}
/// <summary></summary>
public override bool IsIdentified
{
get { return true; }
}
/// <summary></summary>
public override void CreatePrimaryKey()
{
if (!IsOneToMany)
{
PrimaryKey pk = new PrimaryKey();
pk.AddColumns(Identifier.ColumnIterator);
CollectionTable.PrimaryKey = pk;
}
//else // Create an index on the key columns?
}
/// <summary>
///
/// </summary>
/// <param name="mapping"></param>
public override void Validate(IMapping mapping)
{
base.Validate(mapping);
if (!Identifier.IsValid(mapping))
{
throw new MappingException(
string.Format("collection id mapping has wrong number of columns: {0} type: {1}", Role, Identifier.Type.Name));
}
}
}
}