-
Notifications
You must be signed in to change notification settings - Fork 6
/
DbPrimaryKey.cs
76 lines (66 loc) · 2.12 KB
/
DbPrimaryKey.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace DevZest.Data.Addons
{
/// <summary>
/// Represents the database primary key constraint.
/// </summary>
public sealed class DbPrimaryKey : DbTableConstraint, IIndexConstraint
{
internal DbPrimaryKey(Model model, string name, string description, bool isClustered, Func<IList<ColumnSort>> getPrimaryKey)
: base(name, description)
{
Debug.Assert(model != null);
Debug.Assert(getPrimaryKey != null);
Model = model;
IsClustered = isClustered;
_getPrimaryKey = getPrimaryKey;
}
/// <summary>
/// Gets the model of the primary key.
/// </summary>
public Model Model { get; private set; }
/// <summary>
/// Gets a value indicates whether this is a clustered primary key.
/// </summary>
public bool IsClustered { get; private set; }
void IIndexConstraint.AsNonClustered()
{
IsClustered = false;
}
private Func<IList<ColumnSort>> _getPrimaryKey;
private ReadOnlyCollection<ColumnSort> _primaryKey;
/// <summary>
/// Gets the columns with sort direction of this primiary key.
/// </summary>
public ReadOnlyCollection<ColumnSort> PrimaryKey
{
get
{
if (_primaryKey == null)
{
_primaryKey = new ReadOnlyCollection<ColumnSort>(_getPrimaryKey());
_getPrimaryKey = null;
}
return _primaryKey;
}
}
/// <inheritdoc />
public override string SystemName
{
get { return string.IsNullOrEmpty(Name) ? "PrimaryKey" : Name; }
}
/// <inheritdoc />
public override bool IsValidOnTable
{
get { return true; }
}
/// <inheritdoc />
public override bool IsValidOnTempTable
{
get { return true; }
}
}
}