Skip to content

Commit a17749c

Browse files
committed
Fix namespace issues when schema folders are endabled.
Thanks to @audacity76 for issue and preliminary PR.
1 parent feb452c commit a17749c

File tree

19 files changed

+109
-49
lines changed

19 files changed

+109
-49
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ services.AddHandlebarsScaffolding(options =>
166166
};
167167
});
168168
```
169+
170+
## Schema Folders
171+
172+
You can generate models in different folders by database schema.
173+
174+
```csharp
175+
services.AddHandlebarsScaffolding(options =>
176+
{
177+
// Put Models into folders by DB Schema
178+
options.EnableSchemaFolders = true;
179+
});
180+
```
181+
169182
## Embedded Templates
170183

171184
Handlebars templates may be embdedded in a separate .NET Standard project that can be shared among multiple .NET Core scaffolding projects. Simply copy the **CodeTemplates** folder to the .NET Standard project and edit the .csproj file to embed them as a resource in the assembly.

sample/ScaffoldingSample/CodeTemplates/CSharpDbContext/Partials/DbImports.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ using Microsoft.EntityFrameworkCore.Metadata; // Comment
44
{{#if model-namespace}}
55
using {{model-namespace}};
66
{{/if}}
7+
{{#each model-imports}}
8+
using {{model-import}};
9+
{{/each}}

sample/ScaffoldingSample/Contexts/NorthwindSlimContext.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
using System;
22
using Microsoft.EntityFrameworkCore;
33
using Microsoft.EntityFrameworkCore.Metadata; // Comment
4-
using ScaffoldingSample.Models;
4+
using dbo = ScaffoldingSample.Models.dbo;
55

66
namespace ScaffoldingSample.Contexts
77
{ // Comment
88
public partial class NorthwindSlimContext : DbContext
99
{
1010
// My Handlebars Helper
11-
public virtual DbSet<Category> Category { get; set; } = default!;
11+
public virtual DbSet<dbo.Category> Category { get; set; } = default!;
1212
// My Handlebars Helper
13-
public virtual DbSet<Customer> Customer { get; set; } = default!;
13+
public virtual DbSet<dbo.Customer> Customer { get; set; } = default!;
1414
// My Handlebars Helper
15-
public virtual DbSet<CustomerSetting> CustomerSetting { get; set; } = default!;
15+
public virtual DbSet<dbo.CustomerSetting> CustomerSetting { get; set; } = default!;
1616
// My Handlebars Helper
17-
public virtual DbSet<Employee> Employee { get; set; } = default!;
17+
public virtual DbSet<dbo.Employee> Employee { get; set; } = default!;
1818
// My Handlebars Helper
19-
public virtual DbSet<Order> Order { get; set; } = default!;
19+
public virtual DbSet<dbo.Order> Order { get; set; } = default!;
2020
// My Handlebars Helper
21-
public virtual DbSet<OrderDetail> OrderDetail { get; set; } = default!;
21+
public virtual DbSet<dbo.OrderDetail> OrderDetail { get; set; } = default!;
2222
// My Handlebars Helper
23-
public virtual DbSet<Product> Product { get; set; } = default!;
23+
public virtual DbSet<dbo.Product> Product { get; set; } = default!;
2424

2525
public NorthwindSlimContext(DbContextOptions<NorthwindSlimContext> options) : base(options)
2626
{
@@ -38,14 +38,14 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
3838

3939
protected override void OnModelCreating(ModelBuilder modelBuilder)
4040
{
41-
modelBuilder.Entity<Category>(entity =>
41+
modelBuilder.Entity<dbo.Category>(entity =>
4242
{
4343
entity.Property(e => e.CategoryName)
4444
.IsRequired()
4545
.HasMaxLength(15);
4646
});
4747

48-
modelBuilder.Entity<Customer>(entity =>
48+
modelBuilder.Entity<dbo.Customer>(entity =>
4949
{
5050
entity.HasComment("hello table Customer");
5151

@@ -65,7 +65,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6565
entity.Property(e => e.Country).HasMaxLength(15);
6666
});
6767

68-
modelBuilder.Entity<CustomerSetting>(entity =>
68+
modelBuilder.Entity<dbo.CustomerSetting>(entity =>
6969
{
7070
entity.HasKey(e => e.CustomerId)
7171
.HasName("PK_dbo.CustomerSetting");
@@ -80,12 +80,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
8080

8181
entity.HasOne(d => d.Customer)
8282
.WithOne(p => p.CustomerSetting)
83-
.HasForeignKey<CustomerSetting>(d => d.CustomerId)
83+
.HasForeignKey<dbo.CustomerSetting>(d => d.CustomerId)
8484
.OnDelete(DeleteBehavior.ClientSetNull)
8585
.HasConstraintName("FK_CustomerSetting_Customer");
8686
});
8787

88-
modelBuilder.Entity<Employee>(entity =>
88+
modelBuilder.Entity<dbo.Employee>(entity =>
8989
{
9090
entity.Property(e => e.BirthDate).HasColumnType("datetime");
9191

@@ -104,7 +104,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
104104
.HasMaxLength(20);
105105
});
106106

107-
modelBuilder.Entity<Order>(entity =>
107+
modelBuilder.Entity<dbo.Order>(entity =>
108108
{
109109
entity.Property(e => e.CustomerId)
110110
.HasMaxLength(5)
@@ -124,7 +124,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
124124
.HasConstraintName("FK_Orders_Customers");
125125
});
126126

127-
modelBuilder.Entity<OrderDetail>(entity =>
127+
modelBuilder.Entity<dbo.OrderDetail>(entity =>
128128
{
129129
entity.Property(e => e.Quantity).HasDefaultValueSql("((1))");
130130

@@ -143,7 +143,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
143143
.HasConstraintName("FK_Order_Details_Products");
144144
});
145145

146-
modelBuilder.Entity<Product>(entity =>
146+
modelBuilder.Entity<dbo.Product>(entity =>
147147
{
148148
entity.Property(e => e.ProductName)
149149
.IsRequired()

sample/ScaffoldingSample/Contexts/NorthwindSlimContextPartial.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
using System;
22
using Microsoft.EntityFrameworkCore;
33
using ScaffoldingSample.Models;
4+
using dbo = ScaffoldingSample.Models.dbo;
45

56
namespace ScaffoldingSample.Contexts
67
{
78
public partial class NorthwindSlimContext
89
{
910
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
1011
{
11-
modelBuilder.Entity<Employee>()
12+
modelBuilder.Entity<dbo.Employee>()
1213
.Property(e => e.Country)
1314
.HasConversion(
1415
v => v.ToString(),
1516
v => (Country)Enum.Parse(typeof(Country), v));
1617

17-
modelBuilder.Entity<Customer>()
18+
modelBuilder.Entity<dbo.Customer>()
1819
.Property(e => e.Country)
1920
.HasConversion(
2021
v => v.ToString(),

sample/ScaffoldingSample/Models/Category.cs renamed to sample/ScaffoldingSample/Models/dbo/Category.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class Category : EntityBase // My Handlebars Helper
77
{

sample/ScaffoldingSample/Models/Customer.cs renamed to sample/ScaffoldingSample/Models/dbo/Customer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class Customer : EntityBase // My Handlebars Helper
77
{

sample/ScaffoldingSample/Models/CustomerSetting.cs renamed to sample/ScaffoldingSample/Models/dbo/CustomerSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class CustomerSetting : EntityBase // My Handlebars Helper
77
{

sample/ScaffoldingSample/Models/Employee.cs renamed to sample/ScaffoldingSample/Models/dbo/Employee.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class Employee : EntityBase // My Handlebars Helper
77
{

sample/ScaffoldingSample/Models/Order.cs renamed to sample/ScaffoldingSample/Models/dbo/Order.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class Order : EntityBase // My Handlebars Helper
77
{

sample/ScaffoldingSample/Models/OrderDetail.cs renamed to sample/ScaffoldingSample/Models/dbo/OrderDetail.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic; // Comment
33

4-
namespace ScaffoldingSample.Models
4+
namespace ScaffoldingSample.Models.dbo
55
{ // Comment
66
public partial class OrderDetail : EntityBase // My Handlebars Helper
77
{

0 commit comments

Comments
 (0)