forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneToOne.cs
104 lines (93 loc) · 2.27 KB
/
OneToOne.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Mapping
{
/// <summary>
/// A mapping for a <c>one-to-one</c> association.
/// </summary>
[Serializable]
public class OneToOne : ToOne
{
private bool constrained;
private ForeignKeyDirection foreignKeyType;
private IKeyValue identifier;
private string propertyName;
private string entityName;
/// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <param name="owner"></param>
public OneToOne(Table table, PersistentClass owner)
: base(table)
{
identifier = owner.Key;
entityName = owner.EntityName;
}
/// <summary></summary>
public override void CreateForeignKey()
{
if (constrained && referencedPropertyName == null)
{
//TODO: handle the case of a foreign key to something other than the pk
CreateForeignKeyOfEntity(((EntityType)Type).GetAssociatedEntityName());
}
}
/// <summary></summary>
public override IEnumerable<Column> ConstraintColumns => identifier.ColumnIterator.OfType<Column>();
/// <summary></summary>
public bool IsConstrained
{
get { return constrained; }
set { constrained = value; }
}
/// <summary></summary>
public ForeignKeyDirection ForeignKeyType
{
get { return foreignKeyType; }
set { foreignKeyType = value; }
}
/// <summary></summary>
public IKeyValue Identifier
{
get { return identifier; }
set { identifier = value; }
}
/// <summary></summary>
public override bool IsNullable
{
get { return !constrained; }
}
public string EntityName
{
get { return entityName; }
set { entityName = StringHelper.InternedIfPossible(value); }
}
public string PropertyName
{
get { return propertyName; }
set { propertyName = StringHelper.InternedIfPossible(value); }
}
public override IType Type
{
get
{
if (ColumnSpan > 0)
{
return
new SpecialOneToOneType(ReferencedEntityName, foreignKeyType, referencedPropertyName, IsLazy, UnwrapProxy,
entityName, propertyName);
}
else
{
return
TypeFactory.OneToOne(ReferencedEntityName, foreignKeyType, referencedPropertyName, IsLazy, UnwrapProxy,
entityName, propertyName);
}
}
}
}
}