Skip to content

Commit 4a4aaa2

Browse files
author
Anthony Sneed
committed
Fix bug in FileSystemTemplateFileService.RetrieveAllFileNames
1 parent a44c2e2 commit 4a4aaa2

File tree

5 files changed

+66
-23
lines changed

5 files changed

+66
-23
lines changed
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
{{spaces 8}}protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2-
{{spaces 8}}{
3-
{{spaces 12}}if (!optionsBuilder.IsConfigured)
4-
{{spaces 12}}{
5-
{{#if suppress-connectionstring-warning}}
6-
{{spaces 16}}{{sensitive-information-warning}}
7-
{{/if}}
8-
{{spaces 16}}optionsBuilder{{options-builder-provider}};
9-
{{spaces 11}} }
10-
{{spaces 7}} }
1+
{{{on-configuring}}}

sample/ScaffoldingSample/Contexts/NorthwindSlimContext.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public NorthwindSlimContext(DbContextOptions<NorthwindSlimContext> options) : ba
2626
{
2727
}
2828

29+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
30+
{
31+
if (!optionsBuilder.IsConfigured)
32+
{
33+
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
34+
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True");
35+
}
36+
}
37+
38+
2939
protected override void OnModelCreating(ModelBuilder modelBuilder)
3040
{
3141
modelBuilder.Entity<Category>(entity =>
@@ -37,6 +47,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3747

3848
modelBuilder.Entity<Customer>(entity =>
3949
{
50+
entity.HasComment("hello table Customer");
51+
4052
entity.Property(e => e.CustomerId)
4153
.HasMaxLength(5)
4254
.IsFixedLength();
@@ -45,7 +57,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4557

4658
entity.Property(e => e.CompanyName)
4759
.IsRequired()
48-
.HasMaxLength(40);
60+
.HasMaxLength(40)
61+
.HasComment("hello CompanyName");
4962

5063
entity.Property(e => e.ContactName).HasMaxLength(30);
5164

sample/ScaffoldingSample/ScaffoldingDesignTimeServices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using EntityFrameworkCore.Scaffolding.Handlebars;
56
using HandlebarsDotNet;
@@ -19,6 +20,9 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
1920
{
2021
public void ConfigureDesignTimeServices(IServiceCollection services)
2122
{
23+
// Uncomment to launch JIT debugger and hit breakpoints
24+
//Debugger.Launch();
25+
2226
// Add Handlebars scaffolding templates
2327
services.AddHandlebarsScaffolding(options =>
2428
{

src/EntityFrameworkCore.Scaffolding.Handlebars/FileSystemTemplateFileService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public virtual string[] InputFiles(params InputFile[] files)
3737
/// <returns></returns>
3838
public virtual string[] RetrieveAllFileNames(string relativeDirectory)
3939
{
40-
return Directory.GetFiles(relativeDirectory, $"*.{Constants.TemplateExtension}").Select(x => Path.GetFileNameWithoutExtension(x)).ToArray();
40+
return Directory.GetFiles(relativeDirectory, $"*{Constants.TemplateExtension}").Select(x => Path.GetFileNameWithoutExtension(x)).ToArray();
4141
}
4242

4343
/// <summary>

src/EntityFrameworkCore.Scaffolding.Handlebars/HbsCSharpDbContextGenerator.cs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,55 @@ protected override void GenerateOnConfiguring(string connectionString, bool supp
162162
{
163163
Check.NotNull(connectionString, nameof(connectionString));
164164

165-
TemplateData.Add("connection-string", connectionString);
166-
TemplateData.Add("suppress-connectionstring-warning", suppressConnectionStringWarning);
167-
TemplateData.Add("sensitive-information-warning", $"#warning {DesignStrings.SensitiveInformationWarning}");
168-
169-
var useProviderCall = ProviderConfigurationCodeGenerator.GenerateUseProvider(
170-
connectionString,
171-
ProviderConfigurationCodeGenerator.GenerateProviderOptions());
172-
var contextOptions = ProviderConfigurationCodeGenerator.GenerateContextOptions();
173-
if (contextOptions != null)
165+
var sb = new IndentedStringBuilder();
166+
using (sb.Indent())
167+
using (sb.Indent())
174168
{
175-
useProviderCall = useProviderCall.Chain(contextOptions);
169+
sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
170+
sb.AppendLine("{");
171+
172+
using (sb.Indent())
173+
{
174+
sb.AppendLine("if (!optionsBuilder.IsConfigured)");
175+
sb.AppendLine("{");
176+
177+
using (sb.Indent())
178+
{
179+
if (!suppressConnectionStringWarning)
180+
{
181+
sb.DecrementIndent()
182+
.DecrementIndent()
183+
.DecrementIndent()
184+
.DecrementIndent()
185+
.AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
186+
.IncrementIndent()
187+
.IncrementIndent()
188+
.IncrementIndent()
189+
.IncrementIndent();
190+
}
191+
192+
sb.Append("optionsBuilder");
193+
194+
var useProviderCall = ProviderConfigurationCodeGenerator.GenerateUseProvider(
195+
connectionString,
196+
ProviderConfigurationCodeGenerator.GenerateProviderOptions());
197+
var contextOptions = ProviderConfigurationCodeGenerator.GenerateContextOptions();
198+
if (contextOptions != null)
199+
{
200+
useProviderCall = useProviderCall.Chain(contextOptions);
201+
}
202+
203+
sb.Append(CSharpHelper.Fragment(useProviderCall))
204+
.AppendLine(";");
205+
}
206+
sb.AppendLine("}");
207+
}
208+
209+
sb.AppendLine("}");
176210
}
177211

178-
TemplateData.Add("options-builder-provider", CSharpHelper.Fragment(useProviderCall));
212+
var onConfiguring = sb.ToString();
213+
TemplateData.Add("on-configuring", onConfiguring);
179214
}
180215

181216
/// <summary>

0 commit comments

Comments
 (0)