Skip to content

Commit 49654c2

Browse files
committed
Update to EF Core 5.0
- Remove EnablePluralization. - Enable suppression of OnConfiguring.
1 parent a98f8d7 commit 49654c2

File tree

116 files changed

+974
-1013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+974
-1013
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
1010

1111
## Prerequisites
1212

13-
- [Visual Studio 2019](https://www.visualstudio.com/downloads/) 16.4 or greater.
14-
- .[NET Core 3.1 SDK](https://www.microsoft.com/net/download/core).
15-
- [EF Core CLI](https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet).
13+
- [Visual Studio 2019](https://www.visualstudio.com/downloads/) 16.8 Preview 4.0 or greater.
14+
- .[NET Core 5.0 SDK](https://dotnet.microsoft.com/download/dotnet/5.0) RC2 or greater.
15+
- [EF Core CLI 5.0](https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-ef-core-5-rc2/) RC2 or greater.
1616
- Install global `dotnet-ef` tool.
1717
```
18-
dotnet tool install --global dotnet-ef
18+
dotnet tool install --global dotnet-ef --version 5.0.0-rc.2.20475.6
1919
```
2020
- Update global `dotnet-ef` tool.
2121
```
22-
dotnet tool update --global dotnet-ef
22+
dotnet tool update --global dotnet-ef --version 5.0.0-rc.2.20475.6
2323
```
2424
2525
## Database Setup
@@ -42,9 +42,18 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
4242
- `Microsoft.EntityFrameworkCore.SqlServer`
4343
- `Microsoft.EntityFrameworkCore.Design`
4444
45+
```
46+
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6
47+
dotnet add package Microsoft.EntityFrameworkCore.Design --version 5.0.0-rc.2.20475.6
48+
```
49+
4550
3. Add the **EntityFrameworkCore.Scaffolding.Handlebars** NuGet package:
4651
- `EntityFrameworkCore.Scaffolding.Handlebars`
4752
53+
```
54+
dotnet add package EntityFrameworkCore.Scaffolding.Handlebars --version 5.0.0-rc.2
55+
```
56+
4857
4. Remove Class1.cs and add a **ScaffoldingDesignTimeServices** class.
4958
- Implement `IDesignTimeServices` by adding a `ConfigureDesignTimeServices` method
5059
that calls `services.AddHandlebarsScaffolding`.

sample/ScaffoldingSample.Api/Controllers/EmployeeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public EmployeeController(NorthwindSlimContext context)
2121
[HttpGet]
2222
public async Task<ActionResult> Get()
2323
{
24-
var employees = await _context.Employee
24+
var employees = await _context.Employees
2525
.OrderBy(e => e.LastName).ThenBy(e => e.FirstName)
2626
.Select(e => new
2727
{

sample/ScaffoldingSample.Api/ScaffoldingSample.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-rc.2.20475.6" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

sample/ScaffoldingSample.Embedded/Contexts/NorthwindSlimContext.cs

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace ScaffoldingSample.Embedded.Contexts
77
{
88
public partial class NorthwindSlimContext : DbContext
99
{
10-
public virtual DbSet<Category> Category { get; set; }
11-
public virtual DbSet<Customer> Customer { get; set; }
12-
public virtual DbSet<CustomerSetting> CustomerSetting { get; set; }
13-
public virtual DbSet<Employee> Employee { get; set; }
14-
public virtual DbSet<EmployeeTerritories> EmployeeTerritories { get; set; }
15-
public virtual DbSet<Order> Order { get; set; }
16-
public virtual DbSet<OrderDetail> OrderDetail { get; set; }
17-
public virtual DbSet<Product> Product { get; set; }
18-
public virtual DbSet<Territory> Territory { get; set; }
10+
public virtual DbSet<Category> Categories { get; set; }
11+
public virtual DbSet<Customer> Customers { get; set; }
12+
public virtual DbSet<CustomerSetting> CustomerSettings { get; set; }
13+
public virtual DbSet<Employee> Employees { get; set; }
14+
public virtual DbSet<EmployeeTerritory> EmployeeTerritories { get; set; }
15+
public virtual DbSet<Order> Orders { get; set; }
16+
public virtual DbSet<OrderDetail> OrderDetails { get; set; }
17+
public virtual DbSet<Product> Products { get; set; }
18+
public virtual DbSet<Territory> Territories { get; set; }
1919

2020
public NorthwindSlimContext(DbContextOptions<NorthwindSlimContext> options) : base(options)
2121
{
@@ -25,7 +25,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2525
{
2626
if (!optionsBuilder.IsConfigured)
2727
{
28-
//#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.
28+
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
2929
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True");
3030
}
3131
}
@@ -34,16 +34,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3434
{
3535
modelBuilder.Entity<Category>(entity =>
3636
{
37+
entity.ToTable("Category");
38+
39+
entity.HasComment("hello table Customer");
40+
3741
entity.Property(e => e.CategoryName)
3842
.IsRequired()
39-
.HasMaxLength(15);
43+
.HasMaxLength(15)
44+
.HasComment("hello CompanyName");
4045
});
4146

4247
modelBuilder.Entity<Customer>(entity =>
4348
{
49+
entity.ToTable("Customer");
50+
4451
entity.Property(e => e.CustomerId)
4552
.HasMaxLength(5)
46-
.IsFixedLength();
53+
.IsFixedLength(true);
4754

4855
entity.Property(e => e.City).HasMaxLength(15);
4956

@@ -61,9 +68,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6168
entity.HasKey(e => e.CustomerId)
6269
.HasName("PK_dbo.CustomerSetting");
6370

71+
entity.ToTable("CustomerSetting");
72+
6473
entity.Property(e => e.CustomerId)
6574
.HasMaxLength(5)
66-
.IsFixedLength();
75+
.IsFixedLength(true);
6776

6877
entity.Property(e => e.Setting)
6978
.IsRequired()
@@ -78,6 +87,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
7887

7988
modelBuilder.Entity<Employee>(entity =>
8089
{
90+
entity.ToTable("Employee");
91+
8192
entity.Property(e => e.BirthDate).HasColumnType("datetime");
8293

8394
entity.Property(e => e.City).HasMaxLength(15);
@@ -95,7 +106,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
95106
.HasMaxLength(20);
96107
});
97108

98-
modelBuilder.Entity<EmployeeTerritories>(entity =>
109+
modelBuilder.Entity<EmployeeTerritory>(entity =>
99110
{
100111
entity.HasKey(e => new { e.EmployeeId, e.TerritoryId })
101112
.HasName("PK_dbo.EmployeeTerritories");
@@ -115,9 +126,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
115126

116127
modelBuilder.Entity<Order>(entity =>
117128
{
129+
entity.ToTable("Order");
130+
118131
entity.Property(e => e.CustomerId)
119132
.HasMaxLength(5)
120-
.IsFixedLength();
133+
.IsFixedLength(true);
121134

122135
entity.Property(e => e.Freight)
123136
.HasColumnType("money")
@@ -128,50 +141,58 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
128141
entity.Property(e => e.ShippedDate).HasColumnType("datetime");
129142

130143
entity.HasOne(d => d.Customer)
131-
.WithMany(p => p.Order)
144+
.WithMany(p => p.Orders)
132145
.HasForeignKey(d => d.CustomerId)
133146
.HasConstraintName("FK_Orders_Customers");
134147
});
135148

136149
modelBuilder.Entity<OrderDetail>(entity =>
137150
{
151+
entity.ToTable("OrderDetail");
152+
138153
entity.Property(e => e.Quantity).HasDefaultValueSql("((1))");
139154

140155
entity.Property(e => e.UnitPrice).HasColumnType("money");
141156

142157
entity.HasOne(d => d.Order)
143-
.WithMany(p => p.OrderDetail)
158+
.WithMany(p => p.OrderDetails)
144159
.HasForeignKey(d => d.OrderId)
145160
.OnDelete(DeleteBehavior.ClientSetNull)
146161
.HasConstraintName("FK_Order_Details_Orders");
147162

148163
entity.HasOne(d => d.Product)
149-
.WithMany(p => p.OrderDetail)
164+
.WithMany(p => p.OrderDetails)
150165
.HasForeignKey(d => d.ProductId)
151166
.OnDelete(DeleteBehavior.ClientSetNull)
152167
.HasConstraintName("FK_Order_Details_Products");
153168
});
154169

155170
modelBuilder.Entity<Product>(entity =>
156171
{
172+
entity.ToTable("Product");
173+
157174
entity.Property(e => e.ProductName)
158175
.IsRequired()
159176
.HasMaxLength(40);
160177

161-
entity.Property(e => e.RowVersion).IsRowVersion();
178+
entity.Property(e => e.RowVersion)
179+
.IsRowVersion()
180+
.IsConcurrencyToken();
162181

163182
entity.Property(e => e.UnitPrice)
164183
.HasColumnType("money")
165184
.HasDefaultValueSql("((0))");
166185

167186
entity.HasOne(d => d.Category)
168-
.WithMany(p => p.Product)
187+
.WithMany(p => p.Products)
169188
.HasForeignKey(d => d.CategoryId)
170189
.HasConstraintName("FK_Products_Categories");
171190
});
172191

173192
modelBuilder.Entity<Territory>(entity =>
174193
{
194+
entity.ToTable("Territory");
195+
175196
entity.Property(e => e.TerritoryId).HasMaxLength(20);
176197

177198
entity.Property(e => e.TerritoryDescription)

sample/ScaffoldingSample.Embedded/Models/Category.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33

44
namespace ScaffoldingSample.Embedded.Models
55
{
6+
/// <summary>
7+
/// hello table Customer
8+
/// </summary>
69
public partial class Category
710
{
811
public Category()
912
{
10-
Product = new HashSet<Product>();
13+
Products = new HashSet<Product>();
1114
}
1215

1316
public int CategoryId { get; set; }
17+
/// <summary>
18+
/// hello CompanyName
19+
/// </summary>
1420
public string CategoryName { get; set; }
1521

16-
public virtual ICollection<Product> Product { get; set; }
22+
public virtual ICollection<Product> Products { get; set; }
1723
}
1824
}

sample/ScaffoldingSample.Embedded/Models/Customer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public partial class Customer
77
{
88
public Customer()
99
{
10-
Order = new HashSet<Order>();
10+
Orders = new HashSet<Order>();
1111
}
1212

1313
public string CustomerId { get; set; }
@@ -17,6 +17,6 @@ public Customer()
1717
public string Country { get; set; }
1818

1919
public virtual CustomerSetting CustomerSetting { get; set; }
20-
public virtual ICollection<Order> Order { get; set; }
20+
public virtual ICollection<Order> Orders { get; set; }
2121
}
2222
}

sample/ScaffoldingSample.Embedded/Models/Employee.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public partial class Employee
77
{
88
public Employee()
99
{
10-
EmployeeTerritories = new HashSet<EmployeeTerritories>();
10+
EmployeeTerritories = new HashSet<EmployeeTerritory>();
1111
}
1212

1313
public int EmployeeId { get; set; }
@@ -18,6 +18,6 @@ public Employee()
1818
public string City { get; set; }
1919
public string Country { get; set; }
2020

21-
public virtual ICollection<EmployeeTerritories> EmployeeTerritories { get; set; }
21+
public virtual ICollection<EmployeeTerritory> EmployeeTerritories { get; set; }
2222
}
2323
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ScaffoldingSample.Embedded.Models
5+
{
6+
public partial class EmployeeTerritory
7+
{
8+
public int EmployeeId { get; set; }
9+
public string TerritoryId { get; set; }
10+
11+
public virtual Employee Employee { get; set; }
12+
public virtual Territory Territory { get; set; }
13+
}
14+
}

sample/ScaffoldingSample.Embedded/Models/Order.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public partial class Order
77
{
88
public Order()
99
{
10-
OrderDetail = new HashSet<OrderDetail>();
10+
OrderDetails = new HashSet<OrderDetail>();
1111
}
1212

1313
public int OrderId { get; set; }
@@ -18,6 +18,6 @@ public Order()
1818
public decimal? Freight { get; set; }
1919

2020
public virtual Customer Customer { get; set; }
21-
public virtual ICollection<OrderDetail> OrderDetail { get; set; }
21+
public virtual ICollection<OrderDetail> OrderDetails { get; set; }
2222
}
2323
}

sample/ScaffoldingSample.Embedded/Models/Product.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public partial class Product
77
{
88
public Product()
99
{
10-
OrderDetail = new HashSet<OrderDetail>();
10+
OrderDetails = new HashSet<OrderDetail>();
1111
}
1212

1313
public int ProductId { get; set; }
@@ -18,6 +18,6 @@ public Product()
1818
public byte[] RowVersion { get; set; }
1919

2020
public virtual Category Category { get; set; }
21-
public virtual ICollection<OrderDetail> OrderDetail { get; set; }
21+
public virtual ICollection<OrderDetail> OrderDetails { get; set; }
2222
}
2323
}

sample/ScaffoldingSample.Embedded/Models/Territory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public partial class Territory
77
{
88
public Territory()
99
{
10-
EmployeeTerritories = new HashSet<EmployeeTerritories>();
10+
EmployeeTerritories = new HashSet<EmployeeTerritory>();
1111
}
1212

1313
public string TerritoryId { get; set; }
1414
public string TerritoryDescription { get; set; }
1515

16-
public virtual ICollection<EmployeeTerritories> EmployeeTerritories { get; set; }
16+
public virtual ICollection<EmployeeTerritory> EmployeeTerritories { get; set; }
1717
}
1818
}

sample/ScaffoldingSample.Embedded/ScaffoldingDesignTimeServices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.EntityFrameworkCore.Design;
22
using Microsoft.Extensions.DependencyInjection;
3+
using System.Diagnostics;
34
using System.Reflection;
45

56
/*
@@ -13,6 +14,9 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
1314
{
1415
public void ConfigureDesignTimeServices(IServiceCollection services)
1516
{
17+
// Uncomment to launch JIT debugger and hit breakpoints
18+
//Debugger.Launch();
19+
1620
// Get templates assembly
1721
var templatesAssembly = Assembly.Load("TemplatesAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
1822

sample/ScaffoldingSample.Embedded/ScaffoldingSample.Embedded.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-rc.2.20475.6" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-rc.2.20475.6" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

sample/ScaffoldingSample.TypeScript/CodeTemplates/TypeScriptDbContext/DbContext.hbs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)