Skip to content

Commit 1b4781c

Browse files
committed
T4 Template engine is now reliably generating cs files.
1 parent de8332d commit 1b4781c

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

SubSonic.Core.Template/SubSonicDataContext.stt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<#@ include file="SqlServer.ttinclude" #>
33
<#
44
Settings.Host = Host;
5-
Context = new SqlGeneratorContext(Settings.Connection);
5+
using(Context = new SqlGeneratorContext(Settings.Connection))
6+
{
67
#>
78
using Microsoft.Extensions.DependencyInjection;
89
using SubSonic;
@@ -28,5 +29,21 @@ namespace TemplateIntegrationTest.DAL
2829
#>
2930
public ISubSonicSetCollection<Models.<#=table.Name#>> <#=table.Name.Pluralize()#> { get; protected set; }
3031
<#}#>
32+
protected override void OnDbModeling(DbModelBuilder builder)
33+
{
34+
if (builder == null)
35+
{
36+
throw new ArgumentNullException(nameof(builder));
37+
}
38+
<#foreach(Models.Table table in Context.Tables) {
39+
if (Settings.ExcludeTables.Any(x => x.Equals(table.Name, StringComparison.OrdinalIgnoreCase)))
40+
{
41+
continue;
42+
}
43+
#>
44+
builder.AddEntityModel<Models.<#=table.Name#>>();
45+
<#}#>
46+
}
3147
}
32-
}
48+
}
49+
<#}#>

SubSonic.Core.Template/SubSonicDataContext.vstemplate

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<packages repository="extension" repositoryId="SubSonic.Core.VisualStudio.d0e28cfc-1997-48b5-bff3-b1c24fc847ba">
3434
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="3.1.7" />
3535
<package id="Microsoft.Extensions.Logging.Abstractions" version="3.1.7" />
36-
<package id="SubSonic.Core.DAL" version="4.3.0-alpha.6" />
37-
<package id="SubSonic.Extensions.SqlServer" version="4.2.1" />
36+
<package id="SubSonic.Core.DAL" version="4.3.0-alpha.13" />
37+
<package id="SubSonic.Extensions.SqlServer" version="4.3.0-alpha.1" />
3838
</packages>
3939
</WizardData>
4040
</VSTemplate>

SubSonic.Core.Template/SubSonicDataModels.stt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
<#@ import namespace="System.Linq" #>
44
<#
55
Settings.Host = Host;
6-
Context = new SqlGeneratorContext(Settings.Connection);
6+
using (Context = new SqlGeneratorContext(Settings.Connection))
7+
{
78
#>using System;
89
using System.ComponentModel.DataAnnotations;
910
using System.ComponentModel.DataAnnotations.Schema;
11+
using SubSonic;
1012

1113
namespace TemplateIntegrationTest.DAL.Models
1214
{
@@ -17,6 +19,11 @@ namespace TemplateIntegrationTest.DAL.Models
1719
}
1820
#>
1921
[Table("<#=table.Name#>", Schema = "<#=table.Schema#>")]
22+
<#if (Context.TableTypes.Any(x => x.SchemaOwner == table.Schema && x.Name == table.Name)) {
23+
Models.TableType tableType = Context.TableTypes.Single(x => x.SchemaOwner == table.Schema && x.Name == table.Name);
24+
#>
25+
[DbUserDefinedTableType("<#=tableType.Name#>", SchemaName = "<#=tableType.SchemaOwner#>")]
26+
<#}#>
2027
public partial class <#=table.Name#>
2128
{
2229
public <#=table.Name#>() { }
@@ -54,4 +61,5 @@ namespace TemplateIntegrationTest.DAL.Models
5461
}
5562

5663
<#}#>
57-
}
64+
}
65+
<#}#>

0 commit comments

Comments
 (0)