Skip to content

Commit b81ddef

Browse files
committed
split OfficialRazorTemplates
1 parent 3dbb05b commit b81ddef

File tree

5 files changed

+97
-34
lines changed

5 files changed

+97
-34
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@using SmartCode
2+
@using SmartCode.Db
3+
@model BuildContext
4+
@{
5+
var project = Model.Project;
6+
var dbSource = Model.GetDataSource<DbSource>();
7+
var table = Model.GetCurrentTable();
8+
var pkCol = table.PKColumn;
9+
var prefix = dbSource.DbProvider.ParameterPrefix;
10+
var notEqCols = table.Columns.Where(m => m.ConvertedName != m.Name);
11+
var resultMapName = $"{table.ConvertedName}ResultMap";
12+
var queryStatementResultMap = table.HasColNameNotEqConvertedName ? $"ResultMap=\"{resultMapName}\"" : "";
13+
}
14+
15+
<!--获取表映射实体-->
16+
<Statement Id="GetEntity" @(queryStatementResultMap)>
17+
Select T.* From @table.Name As T
18+
<Where>
19+
<IsNotEmpty Prepend="And" Property="@pkCol.ConvertedName">
20+
T.@pkCol.Name= @($"{prefix}{pkCol.ConvertedName}")
21+
</IsNotEmpty>
22+
</Where>
23+
Limit 1
24+
</Statement>

src/SmartCode.CLI/OfficialRazorTemplates/SqlMap-MySql.cshtml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,4 @@
3333
Limit ?Offset,?PageSize
3434
</Statement>
3535
}
36-
@section GetEntity
37-
{
38-
<!--获取表映射实体-->
39-
<Statement Id="GetEntity" @(queryStatementResultMap)>
40-
Select T.* From @table.Name As T
41-
<Where>
42-
<IsNotEmpty Prepend="And" Property="@pkCol.ConvertedName">
43-
T.@pkCol.Name= @($"{prefix}{pkCol.ConvertedName}")
44-
</IsNotEmpty>
45-
</Where>
46-
Limit 1
47-
</Statement>
48-
}
36+

src/SmartCode.CLI/OfficialRazorTemplates/SqlMap-PostgreSql.cshtml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,4 @@
3535
Limit @("@PageSize") Offset @("@Offset")
3636
</Statement>
3737
}
38-
@section GetEntity
39-
{
40-
<!--获取表映射实体-->
41-
<Statement Id="GetEntity" @queryStatementResultMap>
42-
Select T.* From @table.Name T
43-
<Where>
44-
<IsNotEmpty Prepend="And" Property="@pkCol.ConvertedName">
45-
T.@pkCol.Name=@prefix@pkCol.ConvertedName
46-
</IsNotEmpty>
47-
</Where>
48-
Limit 1
49-
</Statement>
50-
}
38+

src/SmartCode.CLI/OfficialRazorTemplates/_SqlMapLayout.cshtml

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,78 @@
2020
<Where>
2121
</Where>
2222
</Statement>
23-
@{ await Html.RenderPartialAsync("SqlMap-Insert.cshtml", Model); }
24-
@{ await Html.RenderPartialAsync("SqlMap-Delete.cshtml", Model); }
25-
@{ await Html.RenderPartialAsync("SqlMap-Update.cshtml", Model); }
26-
@{ await Html.RenderPartialAsync("SqlMap-Query.cshtml", Model); }
2723

28-
@RenderSection("QueryByPage", required: false)
24+
@if (IsSectionDefined("Insert"))
25+
{
26+
await RenderSectionAsync("Insert", required: false);
27+
}
28+
else
29+
{
30+
await Html.RenderPartialAsync("SqlMap-Insert.cshtml", Model);
31+
}
2932

30-
@{ await Html.RenderPartialAsync("SqlMap-GetRecord.cshtml", Model); }
33+
@if (IsSectionDefined("Delete"))
34+
{
35+
await RenderSectionAsync("Delete", required: false);
36+
}
37+
else
38+
{
39+
await Html.RenderPartialAsync("SqlMap-Delete.cshtml", Model);
40+
}
3141

32-
@RenderSection("GetEntity", required: false)
42+
@if (IsSectionDefined("Update"))
43+
{
44+
await RenderSectionAsync("Update", required: false);
45+
}
46+
else
47+
{
48+
await Html.RenderPartialAsync("SqlMap-Update.cshtml", Model);
49+
}
3350

34-
@{ await Html.RenderPartialAsync("SqlMap-IsExist.cshtml", Model); }
51+
@if (IsSectionDefined("Query"))
52+
{
53+
await RenderSectionAsync("Query", required: false);
54+
}
55+
else
56+
{
57+
await Html.RenderPartialAsync("SqlMap-Query.cshtml", Model);
58+
}
59+
60+
@if (IsSectionDefined("QueryByPage"))
61+
{
62+
await RenderSectionAsync("QueryByPage", required: false);
63+
}
64+
else
65+
{
66+
await Html.RenderPartialAsync("SqlMap-QueryByPage.cshtml", Model);
67+
}
68+
69+
@if (IsSectionDefined("GetRecord"))
70+
{
71+
await RenderSectionAsync("GetRecord", required: false);
72+
}
73+
else
74+
{
75+
await Html.RenderPartialAsync("SqlMap-GetRecord.cshtml", Model);
76+
}
77+
78+
@if (IsSectionDefined("GetEntity"))
79+
{
80+
await RenderSectionAsync("GetEntity", required: false);
81+
}
82+
else
83+
{
84+
await Html.RenderPartialAsync("SqlMap-GetEntity.cshtml", Model);
85+
}
86+
87+
@if (IsSectionDefined("IsExist"))
88+
{
89+
await RenderSectionAsync("IsExist", required: false);
90+
}
91+
else
92+
{
93+
await Html.RenderPartialAsync("SqlMap-IsExist.cshtml", Model);
94+
}
3595

3696
</Statements>
3797
</SmartSqlMap>

src/SmartCode.CLI/SmartCode.CLI.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<None Update="OfficialRazorTemplates\Sln.cshtml">
6969
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7070
</None>
71+
<None Update="OfficialRazorTemplates\SqlMap-GetEntity.cshtml">
72+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
73+
</None>
7174
<None Update="OfficialRazorTemplates\_SqlMapLayout.cshtml">
7275
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7376
</None>

0 commit comments

Comments
 (0)