forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHbmMapKey.cs
87 lines (75 loc) · 2.05 KB
/
HbmMapKey.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
79
80
81
82
83
84
85
86
87
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using NHibernate.Util;
namespace NHibernate.Cfg.MappingSchema
{
public partial class HbmMapKey: IColumnsMapping, ITypeMapping
{
#region Implementation of IColumnsMapping
[XmlIgnore]
public IEnumerable<HbmColumn> Columns
{
get { return !ArrayHelper.IsNullOrEmpty(Items) ? Items.OfType<HbmColumn>() : AsColumns(); }
}
#endregion
private IEnumerable<HbmColumn> AsColumns()
{
if (string.IsNullOrEmpty(column))
{
yield break;
}
else
{
yield return new HbmColumn
{
name = column,
length = length,
};
}
}
#region Implementation of IFormulasMapping
[XmlIgnore]
public IEnumerable<HbmFormula> Formulas
{
get { return !ArrayHelper.IsNullOrEmpty(Items) ? Items.OfType<HbmFormula>() : AsFormulas(); }
}
private IEnumerable<HbmFormula> AsFormulas()
{
if (string.IsNullOrEmpty(formula))
{
yield break;
}
else
{
yield return new HbmFormula { Text = new[] { formula } };
}
}
#endregion
#region Implementation of ITypeMapping
public HbmType Type
{
get { return string.IsNullOrEmpty(type) ? null : new HbmType { name = type }; }
}
#endregion
/// <summary>
/// Columns and Formulas, in declared order
/// </summary>
[XmlIgnore]
public IEnumerable<object> ColumnsAndFormulas
{
get
{
if (!ArrayHelper.IsNullOrEmpty(Items) && (!string.IsNullOrEmpty(column) || !string.IsNullOrEmpty(formula)))
throw new MappingException(
"On a map-key: specifying columns or formulas with both attributes and sub-elements is " +
"invalid. Please use only sub-elements, or only one of them as attribute");
if (!string.IsNullOrEmpty(column) && !string.IsNullOrEmpty(formula))
throw new MappingException(
"On a map-key: specifying both column and formula attributes is invalid. Please specify " +
"only one of them, or use sub-elements");
return !ArrayHelper.IsNullOrEmpty(Items) ? Items : AsColumns().Cast<object>().Concat(AsFormulas());
}
}
}
}