-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
TableInformationModel.cs
91 lines (83 loc) · 2.79 KB
/
TableInformationModel.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
namespace EFCorePowerTools.Shared.Models
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using Annotations;
/// <summary>
/// A class holding a certain information about tables.
/// </summary>
[DataContract]
[DebuggerDisplay("{" + nameof(Name) + ",nq}")]
public class TableInformationModel : INotifyPropertyChanged
{
private string _name;
private bool _hasPrimaryKey;
private bool _isKeyLess;
/// <summary>
/// Gets or sets the table name.
/// </summary>
[DataMember]
public string Name
{
get => _name;
set
{
if (value == _name) return;
_name = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets whether a primary key exists for the table or not.
/// </summary>
[DataMember]
public bool HasPrimaryKey
{
get => _hasPrimaryKey;
set
{
if (value == _hasPrimaryKey) return;
_hasPrimaryKey = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets whether a key exists for the table/view or not.
/// </summary>
[IgnoreDataMember]
public bool HasKey
{
get => _isKeyLess;
set
{
if (value == _isKeyLess) return;
_isKeyLess = value;
OnPropertyChanged();
}
}
/// <summary>
/// Initializes a new instance of the <see cref="TableInformationModel"/> class for a specific table.
/// </summary>
/// <param name="name">The table name.</param>
/// <param name="hasPrimaryKey">Whether or not a primary key exists for the table.</param>
/// <exception cref="ArgumentException"><paramref name="schema"/> or <paramref name="name"/> are null or only white spaces.</exception>
public TableInformationModel(string name,
bool hasPrimaryKey)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException(@"Value cannot be empty or only white spaces.", nameof(name));
Name = name;
HasPrimaryKey = hasPrimaryKey;
HasKey = !hasPrimaryKey;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}