-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses.tt
117 lines (94 loc) · 3.27 KB
/
Classes.tt
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
117
<#@ template language="C#v3.5" debug="False" hostspecific="True" #>
<#@ output extension=".cs" #>
<#@ include file="SQLServer.ttinclude" #>
<#
var tables = LoadTables();
#>
using System;
using System.ComponentModel;
using System.Linq;
namespace <#=Namespace#>
{
<# foreach(Table tbl in tables){#>
/// <summary>
/// A class which represents the <#=tbl.Name#> table in the <#=DatabaseName#> Database.
/// This class is queryable through <#=DatabaseName#>DB.<#=tbl.ClassName#>
/// </summary>
public partial class <#=tbl.ClassName#>: INotifyPropertyChanging, INotifyPropertyChanged
{
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
public <#=tbl.ClassName#>(){
OnCreated();
}
#region Properties
<# foreach(var col in tbl.Columns){
if (tbl.ClassName == col.CleanName)
{
col.CleanName += "X";
}
#>
partial void On<#=col.CleanName#>Changing(<#=col.SysType#><#=CheckNullable(col)#> value);
partial void On<#=col.CleanName#>Changed();
private <#=col.SysType#><#=CheckNullable(col)#> _<#=col.CleanName#>;
public <#=col.SysType#><#=CheckNullable(col)#> <#=col.CleanName#> {
get{
return _<#=col.CleanName#>;
}
set{
this.On<#=col.CleanName#>Changing(value);
this.SendPropertyChanging();
this._<#=col.CleanName#> = value;
this.SendPropertyChanged("<#=col.CleanName#>");
this.On<#=col.CleanName#>Changed();
}
}
<# }#>
#endregion
#region Foreign Keys
<#
List<string> fkCreated = new List<string>();
foreach(FKTable fk in tbl.FKTables)
{
if(!ExcludeTables.Contains(fk.OtherTable)){
string propName=fk.OtherQueryable;
if(fkCreated.Contains(propName))
{
propName=fk.OtherQueryable+fkCreated.Count.ToString();
}
fkCreated.Add(fk.OtherQueryable);
#>
public IQueryable<<#=fk.OtherClass #>> <#=propName #>
{
get
{
var db=new <#=Namespace #>.<#=DatabaseName#>DB();
return from items in db.<#=fk.OtherQueryable #>
where items.<#=fk.OtherColumn#> == _<#=fk.ThisColumn#>
select items;
}
}
<#
}
}
#>
#endregion
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
var handler = PropertyChanging;
if (handler != null)
handler(this, emptyChangingEventArgs);
}
protected virtual void SendPropertyChanged(String propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
<#}#>
}