Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions EntityFrameworkCore.Scaffolding.Handlebars.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{B16E9B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample", "sample\ScaffoldingSample\ScaffoldingSample.csproj", "{02EC28F3-AA15-4429-9D49-6CE1F2ACCEFA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.Api", "sample\ScaffoldingSample.Api\ScaffoldingSample.Api.csproj", "{6141959E-72B2-4FA5-AE75-E0053BFE16D1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.TypeScript", "sample\ScaffoldingSample.TypeScript\ScaffoldingSample.TypeScript.csproj", "{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemplatesAssembly", "sample\TemplatesAssembly\TemplatesAssembly.csproj", "{BA4575F5-1DDF-4E7D-A06E-09E56703C3FA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.Embedded", "sample\ScaffoldingSample.Embedded\ScaffoldingSample.Embedded.csproj", "{9288FD98-43FC-4E6B-87FC-FC43E8071C07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScaffoldingSample.Api", "sample\ScaffoldingSample.Api\ScaffoldingSample.Api.csproj", "{6D11B09D-28D2-47F5-B49B-4493C3051EF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,10 +47,6 @@ Global
{02EC28F3-AA15-4429-9D49-6CE1F2ACCEFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02EC28F3-AA15-4429-9D49-6CE1F2ACCEFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02EC28F3-AA15-4429-9D49-6CE1F2ACCEFA}.Release|Any CPU.Build.0 = Release|Any CPU
{6141959E-72B2-4FA5-AE75-E0053BFE16D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6141959E-72B2-4FA5-AE75-E0053BFE16D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6141959E-72B2-4FA5-AE75-E0053BFE16D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6141959E-72B2-4FA5-AE75-E0053BFE16D1}.Release|Any CPU.Build.0 = Release|Any CPU
{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -63,6 +59,10 @@ Global
{9288FD98-43FC-4E6B-87FC-FC43E8071C07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9288FD98-43FC-4E6B-87FC-FC43E8071C07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9288FD98-43FC-4E6B-87FC-FC43E8071C07}.Release|Any CPU.Build.0 = Release|Any CPU
{6D11B09D-28D2-47F5-B49B-4493C3051EF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D11B09D-28D2-47F5-B49B-4493C3051EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D11B09D-28D2-47F5-B49B-4493C3051EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D11B09D-28D2-47F5-B49B-4493C3051EF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -71,10 +71,10 @@ Global
{C8D8B5AB-0F65-4C22-AC7A-BB1350043757} = {CE438F3D-E03D-4DF5-A4A1-6FA57576F9A4}
{CF5E7978-FC4B-4620-8CDF-EA622B6159C0} = {0C310C69-DDCB-4A47-A286-601C74BE5D96}
{02EC28F3-AA15-4429-9D49-6CE1F2ACCEFA} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
{6141959E-72B2-4FA5-AE75-E0053BFE16D1} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
{BA4575F5-1DDF-4E7D-A06E-09E56703C3FA} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
{9288FD98-43FC-4E6B-87FC-FC43E8071C07} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
{6D11B09D-28D2-47F5-B49B-4493C3051EF1} = {B16E9B06-FE29-413E-B98F-6123DCB92394}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {15011E43-4689-4DD6-A1F4-C388E5012B58}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
## Prerequisites

- [Visual Studio 2022](https://www.visualstudio.com/downloads/) or greater, [JetBrains Rider](https://www.jetbrains.com/rider) 2022.2 or greater.
- [.NET 7.0 SDK](https://dotnet.microsoft.com/download/dotnet/7.0) or greater.
- [EF Core CLI 7.0](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) or greater.
- [.NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet) or greater.
- [EF Core CLI 8.0](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) or greater.
- Install global `dotnet-ef` tool.
```
dotnet tool install --global dotnet-ef
Expand All @@ -37,10 +37,10 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht

## Upgrading

1. Upgrade `TargetFramework` in **.csproj** file to `net6.0` or `net7.0`.
1. Upgrade `TargetFramework` in **.csproj** file to `net8.0`.
- Optional: Set `ImplicitUsings` to `enable`.
- Optional: Set `Nullable` ro `enable`.
2. Update the following NuGet packages to `7.0.0` or later:
2. Update the following NuGet packages to `8.0.0` or later:
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.SqlServer
- EntityFrameworkCore.Scaffolding.Handlebars
Expand All @@ -52,7 +52,7 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht

## Usage

1. Create a new **.NET 6** or **.NET 7** class library.
1. Create a new **.NET 8** class library.

2. Add EF Core SQL Server and Tools NuGet packages.
- `Microsoft.EntityFrameworkCore.SqlServer`
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
54 changes: 22 additions & 32 deletions sample/ScaffoldingSample.Api/Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ScaffoldingSample.Contexts;

namespace ScaffoldingSample.Api.Controllers
namespace ScaffoldingSample.Api.Controllers;

[Route("api/[controller]")]
[ApiController]
public class EmployeeController(NorthwindSlimContext context) : ControllerBase
{
[Route("api/[controller]")]
[ApiController]
public class EmployeeController : ControllerBase
// GET api/employee
[HttpGet]
public async Task<ActionResult> Get()
{
private readonly NorthwindSlimContext _context;

public EmployeeController(NorthwindSlimContext context)
{
_context = context;
}

// GET api/employee
[HttpGet]
public async Task<ActionResult> Get()
{
var employees = await _context.Employees
.OrderBy(e => e.LastName).ThenBy(e => e.FirstName)
.Select(e => new
{
e.EmployeeId,
e.LastName,
e.FirstName,
BirthDate = e.BirthDate.GetValueOrDefault().ToShortDateString(),
HireDate = e.HireDate.GetValueOrDefault().ToShortDateString(),
Country = e.Country.ToString()
})
.ToListAsync();
return Ok(employees);
}
var employees = await context.Employees
.OrderBy(e => e.LastName).ThenBy(e => e.FirstName)
.Select(e => new
{
e.EmployeeId,
e.LastName,
e.FirstName,
BirthDate = e.BirthDate.GetValueOrDefault().ToShortDateString(),
HireDate = e.HireDate.GetValueOrDefault().ToShortDateString(),
e.Country
})
.ToListAsync();
return Ok(employees);
}
}
}
42 changes: 26 additions & 16 deletions sample/ScaffoldingSample.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using ScaffoldingSample.Contexts;

namespace ScaffoldingSample.Api
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
builder.Services.AddDbContext<NorthwindSlimContext>(options =>
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
var connectionString = builder.Configuration.GetConnectionString(nameof(NorthwindSlimContext));
options.UseSqlServer(connectionString);
});

var app = builder.Build();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.MapControllers();

app.Run();
25 changes: 10 additions & 15 deletions sample/ScaffoldingSample.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49638",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "api/employee",
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5041",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ScaffoldingSample.Api": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "api/employee",
"applicationUrl": "http://localhost:5000",
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7208;http://localhost:5041",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}
15 changes: 12 additions & 3 deletions sample/ScaffoldingSample.Api/ScaffoldingSample.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>false</InvariantGlobalization>
<UserSecretsId>12811259-bfae-451f-9a72-050791c4ed4b</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions sample/ScaffoldingSample.Api/ScaffoldingSample.Api.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@SaffoldingSample.Api_HostAddress = http://localhost:5041

GET {{SaffoldingSample.Api_HostAddress}}/weatherforecast/
Accept: application/json

###
25 changes: 25 additions & 0 deletions sample/ScaffoldingSample.Api/ScaffoldingSample.Api.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.Api", "ScaffoldingSample.Api.csproj", "{E841BA04-0CB7-46A9-8CE5-02049F3A499C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E841BA04-0CB7-46A9-8CE5-02049F3A499C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E841BA04-0CB7-46A9-8CE5-02049F3A499C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E841BA04-0CB7-46A9-8CE5-02049F3A499C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E841BA04-0CB7-46A9-8CE5-02049F3A499C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB5CBEB7-A02F-48C9-BD88-FC41367DDFB2}
EndGlobalSection
EndGlobal
51 changes: 0 additions & 51 deletions sample/ScaffoldingSample.Api/Startup.cs

This file was deleted.

5 changes: 2 additions & 3 deletions sample/ScaffoldingSample.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
3 changes: 2 additions & 1 deletion sample/ScaffoldingSample.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading