This repository was archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModel.tt
More file actions
87 lines (77 loc) · 2.53 KB
/
Copy pathModel.tt
File metadata and controls
87 lines (77 loc) · 2.53 KB
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
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".Generated.cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text" #>
<#@ include file="Settings.ttinclude" once="true"#><##>
<#@ include file="..\..\T4SSDT.ttinclude" once="true"#><##>
//------------------------------------------------------------------------------
// <auto-generated>
// T4SSDT Data access layer code generator.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.CodeDom.Compiler;
using System.Data;
namespace Model
{
<#
var hostServiceProvider = (IServiceProvider)this.Host;
var dte = (DTE)hostServiceProvider.GetService(typeof(DTE));
TSqlModel model = null;
foreach (Project project in dte.Solution)
{
if (project.Kind == "{00d1a9c2-b5f0-4af3-8072-f6c62b433612}")
{
model = GenerateModelFromProjectItems(project.ProjectItems);
break;
}
}
if (null == model)
Error("Database project was not found!");
/********************************************** POCO GENERATOR *********************************************/
void RenderPoco(string name, ColumnInfo[] columns, ColumnInfo[] primaryKey = null)
{
#>
[GeneratedCode("T4SSDT", "1.0")]
public partial struct <#= name#>
{
<# foreach (var column in columns.Where(c => !ExcludeFromPOCO.Contains(c.FullName))) { #>
public <#= column.TypeName#> <#= column.FieldName#> { get; set; }
<# } #>
}
<#
}
void RenderTableTypePoco(string name, ColumnInfo[] columns)
{
#>
[GeneratedCode("T4SSDT", "1.0")]
public partial class <#= name#> : DataTable
{
public <#= name#>()
{
<# foreach (var column in columns) { #>
Columns.Add("<#= column.FieldName#>", typeof(<#= column.TypeName#>));
<# } #>
}
public void AddRow(
<#=string.Join(", \r\n ",
columns.Select(c => c.TypeName + " " + ToCamelCase(c.FieldName)))#>)
{
Rows.Add(
<#=string.Join(", \r\n ", columns.Select(c => ToCamelCase(c.FieldName)))#>);
}
}
<#
}
ForEachTable(model, RenderPoco, ExcludeFromPOCO);
ForEachView(model, RenderPoco, ExcludeFromPOCO);
ForEachTableType(model, RenderTableTypePoco, ExcludeFromPOCO);
model.Dispose();
#>
}