Skip to content

Commit 7e90831

Browse files
authored
chore: adding sample applications (#27)
1 parent f801649 commit 7e90831

68 files changed

Lines changed: 2204 additions & 85 deletions

File tree

Some content is hidden

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

samples/README.md

Lines changed: 236 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ This directory contains sample projects demonstrating various usage patterns of
44

55
## Sample Overview
66

7-
| Sample | Input Mode | SQL SDK / Provider | Key Features |
8-
|--------|------------|-------------------|--------------|
9-
| [simple-generation](#simple-generation) | DACPAC | Traditional SQL Project (.sqlproj) | Basic usage, direct source import |
10-
| [msbuild-sdk-sql-proj-generation](#msbuild-sdk-sql-proj-generation) | DACPAC | MSBuild.Sdk.SqlProj (.csproj) | Modern cross-platform SQL SDK |
11-
| [split-data-and-models-between-multiple-projects](#split-outputs) | DACPAC | Traditional SQL Project (.sqlproj) | Clean architecture, split outputs |
12-
| [connection-string-sqlite](#connection-string-sqlite) | Connection String | SQLite | Direct database reverse engineering |
7+
### DACPAC Mode Samples
8+
9+
| Sample | SQL SDK / Provider | Key Features |
10+
|--------|-------------------|--------------|
11+
| [microsoft-build-sql-zero-config](#microsoft-build-sql-zero-config) | Microsoft.Build.Sql | **Zero-config** with official MS SDK |
12+
| [dacpac-zero-config](#dacpac-zero-config) | Pre-built .dacpac | **Zero-config** direct DACPAC |
13+
| [simple-generation](#simple-generation) | Traditional SQL Project (.sqlproj) | Basic usage, direct source import |
14+
| [msbuild-sdk-sql-proj-generation](#msbuild-sdk-sql-proj-generation) | MSBuild.Sdk.SqlProj (.csproj) | Modern cross-platform SQL SDK |
15+
| [split-data-and-models-between-multiple-projects](#split-outputs) | Traditional SQL Project (.sqlproj) | Clean architecture, split outputs |
16+
| [custom-renaming](#custom-renaming) | Microsoft.Build.Sql | Entity/property renaming rules |
17+
| [schema-organization](#schema-organization) | Microsoft.Build.Sql | Schema-based folders and namespaces |
18+
19+
### Connection String Mode Samples
20+
21+
| Sample | Database Provider | Key Features |
22+
|--------|------------------|--------------|
23+
| [connection-string-sqlite](#connection-string-sqlite) | SQLite | Direct database reverse engineering |
24+
| [connection-string-mssql](#connection-string-mssql) | SQL Server + Aspire | SQL Server container with .NET Aspire |
25+
| [aspnet-core-appsettings](#aspnet-core-appsettings) | SQL Server + Aspire | appsettings.json + Aspire container |
1326

1427
## Input Modes
1528

@@ -44,28 +57,47 @@ JD.Efcpt.Build supports multiple SQL Project SDKs:
4457
### 2. Connection String Mode
4558
Reverse engineers directly from a live database connection.
4659

47-
```xml
48-
<PropertyGroup>
49-
<EfcptConnectionString>Data Source=./database.db</EfcptConnectionString>
50-
<EfcptProvider>sqlite</EfcptProvider>
51-
</PropertyGroup>
52-
```
60+
---
61+
62+
## Sample Details
5363

54-
#### Supported Providers
64+
### microsoft-build-sql-zero-config
5565

56-
| Provider | Value | NuGet Package Used |
57-
|----------|-------|-------------------|
58-
| SQL Server | `mssql` | Microsoft.Data.SqlClient |
59-
| PostgreSQL | `postgres` | Npgsql |
60-
| MySQL/MariaDB | `mysql` | MySqlConnector |
61-
| SQLite | `sqlite` | Microsoft.Data.Sqlite |
62-
| Oracle | `oracle` | Oracle.ManagedDataAccess.Core |
63-
| Firebird | `firebird` | FirebirdSql.Data.FirebirdClient |
64-
| Snowflake | `snowflake` | Snowflake.Data |
66+
**Location:** `microsoft-build-sql-zero-config/`
67+
68+
Demonstrates true **zero-configuration** usage with Microsoft's official `Microsoft.Build.Sql` SDK. Just add JD.Efcpt.Build to your project - no efcpt-config.json, no templates, no project references needed.
69+
70+
**Key Features:**
71+
- **Zero configuration** - no efcpt-config.json, templates, or project references
72+
- Uses Microsoft's official `Microsoft.Build.Sql` SDK (cross-platform)
73+
- Automatic SQL project discovery from solution
74+
- Default sensible configuration applied automatically
75+
76+
**Build:**
77+
```bash
78+
dotnet build microsoft-build-sql-zero-config/ZeroConfigMsBuildSql.sln
79+
```
6580

6681
---
6782

68-
## Sample Details
83+
### dacpac-zero-config
84+
85+
**Location:** `dacpac-zero-config/`
86+
87+
Demonstrates **zero-configuration** reverse engineering directly from a pre-built `.dacpac` file. Ideal when you receive a DACPAC from a DBA or CI/CD pipeline.
88+
89+
**Key Features:**
90+
- **Zero configuration** - no efcpt-config.json or templates
91+
- Uses pre-built DACPAC file (no SQL project in solution)
92+
- Simply set `EfcptDacpac` property to point to the .dacpac file
93+
- No build step for SQL project - just reverse engineering
94+
95+
**Build:**
96+
```bash
97+
dotnet build dacpac-zero-config/ZeroConfigDacpac.sln
98+
```
99+
100+
---
69101

70102
### simple-generation
71103

@@ -136,12 +168,113 @@ split-data-and-models-between-multiple-projects/
136168
- DbContext and configurations go to Data project
137169
- Automatic file distribution during build
138170

139-
**Configuration (Models project):**
140-
```xml
141-
<PropertyGroup>
142-
<EfcptSplitOutputs>true</EfcptSplitOutputs>
143-
<EfcptDataProject>..\SampleApp.Data\SampleApp.Data.csproj</EfcptDataProject>
144-
</PropertyGroup>
171+
---
172+
173+
### custom-renaming
174+
175+
**Location:** `custom-renaming/`
176+
177+
Demonstrates using `efcpt.renaming.json` to rename database objects to clean C# names. Useful for legacy databases with naming conventions like `tbl` prefixes or `snake_case` columns.
178+
179+
```
180+
custom-renaming/
181+
├── DatabaseProject/ # SQL Project with legacy-named tables
182+
│ └── dbo/Tables/
183+
│ ├── tblCustomers.sql # Legacy tbl prefix
184+
│ ├── tblOrders.sql
185+
│ └── tblOrderItems.sql
186+
├── EntityFrameworkCoreProject/
187+
│ ├── EntityFrameworkCoreProject.csproj
188+
│ ├── efcpt-config.json
189+
│ └── efcpt.renaming.json # Renaming rules
190+
└── CustomRenaming.sln
191+
```
192+
193+
**Key Features:**
194+
- Renames tables: `tblCustomers``Customer`
195+
- Renames columns: `cust_id``Id`, `cust_first_name``FirstName`
196+
- Renaming file is auto-discovered by convention
197+
- Schema-level `UseSchemaName` setting
198+
199+
**Configuration (efcpt.renaming.json):**
200+
```json
201+
[
202+
{
203+
"SchemaName": "dbo",
204+
"UseSchemaName": false,
205+
"Tables": [
206+
{
207+
"Name": "tblCustomers",
208+
"NewName": "Customer",
209+
"Columns": [
210+
{ "Name": "cust_id", "NewName": "Id" },
211+
{ "Name": "cust_first_name", "NewName": "FirstName" }
212+
]
213+
}
214+
]
215+
}
216+
]
217+
```
218+
219+
**Build:**
220+
```bash
221+
dotnet build custom-renaming/CustomRenaming.sln
222+
```
223+
224+
---
225+
226+
### schema-organization
227+
228+
**Location:** `schema-organization/`
229+
230+
Demonstrates organizing generated entities by database schema using folder and namespace organization.
231+
232+
```
233+
schema-organization/
234+
├── DatabaseProject/
235+
│ ├── dbo/Tables/Customer.sql
236+
│ ├── sales/Tables/Order.sql
237+
│ ├── sales/Tables/OrderItem.sql
238+
│ ├── inventory/Tables/Product.sql
239+
│ └── inventory/Tables/Warehouse.sql
240+
├── EntityFrameworkCoreProject/
241+
│ ├── EntityFrameworkCoreProject.csproj
242+
│ └── efcpt-config.json
243+
└── SchemaOrganization.sln
244+
```
245+
246+
**Key Features:**
247+
- `use-schema-folders-preview`: Creates subdirectories per schema (`Models/dbo/`, `Models/sales/`)
248+
- `use-schema-namespaces-preview`: Adds schema to namespace (`EntityFrameworkCoreProject.Models.Sales`)
249+
- Useful for large databases with multiple schemas
250+
251+
**Generated Output:**
252+
```
253+
obj/efcpt/Generated/Models/
254+
├── dbo/
255+
│ └── Customer.g.cs # namespace: *.Models.Dbo
256+
├── sales/
257+
│ ├── Order.g.cs # namespace: *.Models.Sales
258+
│ └── OrderItem.g.cs
259+
└── inventory/
260+
├── Product.g.cs # namespace: *.Models.Inventory
261+
└── Warehouse.g.cs
262+
```
263+
264+
**Configuration (efcpt-config.json):**
265+
```json
266+
{
267+
"file-layout": {
268+
"output-path": "Models",
269+
"use-schema-folders-preview": true,
270+
"use-schema-namespaces-preview": true
271+
}
272+
}
273+
```
274+
275+
**Build:**
276+
```bash
277+
dotnet build schema-organization/SchemaOrganization.sln
145278
```
146279

147280
---
@@ -152,33 +285,90 @@ split-data-and-models-between-multiple-projects/
152285

153286
Demonstrates connection string mode with SQLite - no SQL Project needed, reverse engineers directly from a database.
154287

288+
---
289+
290+
### connection-string-mssql
291+
292+
**Location:** `connection-string-mssql/`
293+
294+
Demonstrates connection string mode with SQL Server using .NET Aspire to manage a SQL Server container.
295+
155296
```
156-
connection-string-sqlite/
297+
connection-string-mssql/
298+
├── ConnectionStringMssql.AppHost/ # Aspire orchestrator
299+
├── EntityFrameworkCoreProject/ # EF Core project with JD.Efcpt.Build
157300
├── Database/
158-
│ ├── sample.db # SQLite database file
159-
│ └── schema.sql # Schema documentation
160-
├── EntityFrameworkCoreProject/
161-
│ ├── EntityFrameworkCoreProject.csproj
162-
│ ├── efcpt-config.json
163-
│ └── Template/
164-
├── setup-database.ps1 # Creates sample database
165-
└── README.md
301+
│ └── init.sql # Database initialization
302+
└── ConnectionStringMssql.sln
166303
```
167304

168-
**Setup:**
169-
```powershell
170-
./setup-database.ps1 # Creates Database/sample.db
305+
**Key Features:**
306+
- SQL Server runs in Docker, managed by Aspire
307+
- No external database dependencies
308+
- Uses `EfcptProvider` and `EfcptConnectionString` properties
309+
310+
**Quick Start:**
311+
```bash
312+
# 1. Start the SQL Server container
313+
dotnet run --project ConnectionStringMssql.AppHost
314+
315+
# 2. Initialize the database
316+
sqlcmd -S localhost,11433 -U sa -P "YourStrong@Passw0rd" -i Database/init.sql
317+
318+
# 3. Build the EF Core project
171319
dotnet build EntityFrameworkCoreProject
172320
```
173321

174-
**Key Configuration:**
322+
**Prerequisites:** Docker Desktop, .NET 9.0 SDK
323+
324+
---
325+
326+
### aspnet-core-appsettings
327+
328+
**Location:** `aspnet-core-appsettings/`
329+
330+
Demonstrates reading connection strings from `appsettings.json` with .NET Aspire managing the SQL Server container.
331+
332+
```
333+
aspnet-core-appsettings/
334+
├── AspNetCoreAppSettings.AppHost/ # Aspire orchestrator
335+
├── MyApp.Api/
336+
│ ├── MyApp.Api.csproj
337+
│ ├── appsettings.json # Connection string for build
338+
│ └── Program.cs
339+
├── Database/
340+
│ └── init.sql # Database initialization
341+
└── AspNetCoreAppSettings.sln
342+
```
343+
344+
**Key Features:**
345+
- Uses `EfcptAppSettings` to read connection string from appsettings.json
346+
- SQL Server runs in Docker, managed by Aspire
347+
- Works with ASP.NET Core configuration patterns
348+
349+
**Configuration (csproj):**
175350
```xml
176351
<PropertyGroup>
177-
<EfcptConnectionString>Data Source=$(MSBuildProjectDirectory)\..\Database\sample.db</EfcptConnectionString>
178-
<EfcptProvider>sqlite</EfcptProvider>
352+
<EfcptAppSettings>appsettings.json</EfcptAppSettings>
353+
<EfcptConnectionStringName>DefaultConnection</EfcptConnectionStringName>
354+
<EfcptProvider>mssql</EfcptProvider>
179355
</PropertyGroup>
180356
```
181357

358+
**Quick Start:**
359+
```bash
360+
# 1. Start the SQL Server container
361+
dotnet run --project AspNetCoreAppSettings.AppHost
362+
363+
# 2. Initialize the database
364+
sqlcmd -S localhost,11434 -U sa -P "YourStrong@Passw0rd" -i Database/init.sql
365+
366+
# 3. Build the API project
367+
dotnet build MyApp.Api
368+
```
369+
370+
**Prerequisites:** Docker Desktop, .NET 9.0 SDK
371+
182372
---
183373

184374
## Common Configuration
@@ -189,6 +379,8 @@ All samples use:
189379
- **efcpt.renaming.json** for entity/property renaming rules (optional)
190380
- **Fingerprint-based incremental builds** - only regenerates when schema changes
191381

382+
> **Note:** The zero-config samples (`microsoft-build-sql-zero-config` and `dacpac-zero-config`) use sensible defaults and don't require any configuration files.
383+
192384
## Getting Started
193385

194386
1. Clone the repository
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.1.0" />
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
<TargetFramework>net9.0</TargetFramework>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<UserSecretsId>aspnet-core-appsettings-apphost</UserSecretsId>
10+
<!-- Disable JD.Efcpt.Build for AppHost -->
11+
<EfcptEnabled>false</EfcptEnabled>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.1.0" />
16+
<PackageReference Include="Aspire.Hosting.SqlServer" Version="9.1.0" />
17+
</ItemGroup>
18+
19+
<!-- No ProjectReference to API project - we only need to start the SQL Server container -->
20+
21+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
// Add SQL Server container with a fixed port for build-time code generation
4+
var sqlServer = builder.AddSqlServer("sql", port: 11434)
5+
.WithLifetime(ContainerLifetime.Persistent);
6+
7+
// Add the MyAppDb database (will be created automatically)
8+
sqlServer.AddDatabase("MyAppDb");
9+
10+
builder.Build().Run();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyApp.Api", "MyApp.Api\MyApp.Api.csproj", "{B2C3D4E5-F6A7-8901-BCDE-F12345678901}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreAppSettings.AppHost", "AspNetCoreAppSettings.AppHost\AspNetCoreAppSettings.AppHost.csproj", "{C3D4E5F6-A7B8-9012-CDEF-234567890123}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{C3D4E5F6-A7B8-9012-CDEF-234567890123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{C3D4E5F6-A7B8-9012-CDEF-234567890123}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{C3D4E5F6-A7B8-9012-CDEF-234567890123}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{C3D4E5F6-A7B8-9012-CDEF-234567890123}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)