-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableStruct.cs
116 lines (102 loc) · 3.47 KB
/
TableStruct.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
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DBUtil
{
/// <summary>
/// 表结构描述类(实验中...)
/// </summary>
public class TableStruct
{
public string Name { set; get; }
public string Desc { set; get; }
public string PrimaryKey { set; get; }
public List<Column> Columns = new List<Column>();
public List<Constraint> Constraints = new List<Constraint>();
public List<Trigger> Triggers = new List<Trigger>();
public List<Index> Indexs = new List<Index>();
public class Column
{
public string Name { set; get; }
public string Type { set; get; }
public string FinalType
{
get
{
if ((Type.Contains("binary")
|| Type.Contains("char")
|| Type == "datetime2"
|| Type == "datetimeoffset"
|| Type == "decimal"
|| Type == "numeric"
|| Type == "time")
&& (!Type.Contains("(")))
{
//采取的是Type和MaxLength分离的方式
return Type + "(" + (MaxLength == -1 ? "max" : MaxLength.ToString()) + ")";
}
else
{
return Type;
}
}
}
public string IdentityStr { set; get; }
public string FinalIdentity
{
get
{
if (!string.IsNullOrWhiteSpace(IdentityStr))
{
return IdentityStr;
}
return IsIdentity ? "identity(" + (Start == 0 ? 1 : Start).ToString() + "," + (Incre == 0 ? 1 : Incre).ToString() + ")" : "";
}
}
public string Desc { set; get; }
public bool IsIdentity { set; get; }
public bool IsNullable { set; get; }
public bool IsPrimaryKey { set; get; }
public string Default { set; get; }
public int MaxLength { set; get; }
public int Start { set; get; }
public int Incre { set; get; }
public bool IsUnique { set; get; }
}
public class Constraint
{
public string Name { set; get; }
public string Type { set; get; }
public string DelType { set; get; }
public string UpdateType { set; get; }
public string Keys { set; get; }
public string RefStr { set; get; }
public string Remark { set; get; }
}
public class Trigger
{
public string Name { set; get; }
public string Type { set; get; }
}
public class Index
{
public string Name { set; get; }
public string Desc { set; get; }
public string Keys { set; get; }
}
}
public class Proc
{
public string Name { set; get; }
public string LastUpdate { set; get; }
public string CreateSql { set; get; }
}
public class Func
{
public string Name { set; get; }
public string Type { set; get; }
public string LastUpdate { set; get; }
public string CreateSql { set; get; }
}
}