Skip to content

Commit e109225

Browse files
committed
Merge branch 'master' into net10
2 parents a6968e6 + 9bdd75c commit e109225

File tree

239 files changed

+53698
-11329
lines changed

Some content is hidden

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

239 files changed

+53698
-11329
lines changed

.github/copilot-instructions.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Pomelo.EntityFrameworkCore.MySql
2+
3+
Pomelo.EntityFrameworkCore.MySql is the most popular Entity Framework Core provider for MySQL compatible databases. It supports EF Core 10.0 and uses MySqlConnector for high-performance database server communication. The repository contains multiple NuGet packages and a comprehensive test suite.
4+
5+
Always reference these instructions first and only fallback to search or bash commands when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Prerequisites and Setup
10+
- Install .NET 10.0.100 SDK: `curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 10.0.100`
11+
- Add to PATH: `export PATH="$HOME/.dotnet:$PATH"`
12+
- Install EF Core tools: `dotnet tool restore` (takes ~1-2 seconds)
13+
- **CRITICAL**: Create `/tmp/nuget.config` with clean NuGet sources due to network access issues:
14+
```xml
15+
<?xml version="1.0" encoding="utf-8"?>
16+
<configuration>
17+
<packageSources>
18+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
19+
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
20+
</packageSources>
21+
<config>
22+
<add key="disableNugetaudit" value="true" />
23+
</config>
24+
</configuration>
25+
```
26+
27+
### Build Commands (All Validated and Timed)
28+
- **Package restore**: `dotnet restore --configfile /tmp/nuget.config --disable-parallel --no-cache --property WarningsAsErrors= --property TreatWarningsAsErrors=false` (takes ~2 seconds)
29+
- **Debug build**: `dotnet build -c Debug --no-restore` (takes ~4 seconds). NEVER CANCEL: Set timeout to 10+ minutes.
30+
- **Release build**: `dotnet build -c Release --no-restore` (takes ~11 seconds). NEVER CANCEL: Set timeout to 15+ minutes.
31+
- **Setup test configs**: Required before building - copy example config files:
32+
```bash
33+
cp test/EFCore.MySql.FunctionalTests/config.json.example test/EFCore.MySql.FunctionalTests/config.json
34+
cp test/EFCore.MySql.IntegrationTests/config.json.example test/EFCore.MySql.IntegrationTests/config.json
35+
```
36+
37+
### Test Suite Overview
38+
The repository has multiple test projects with different database requirements:
39+
40+
- **EFCore.MySql.Tests** (77 tests): True unit tests, NO database required. Takes ~3 seconds.
41+
- **EFCore.MySql.FunctionalTests**: Database integration tests. REQUIRES MySQL database.
42+
- **EFCore.MySql.IntegrationTests**: Full application integration tests with ASP.NET Core. REQUIRES MySQL database and complex setup.
43+
44+
### Database Setup for Tests
45+
**CRITICAL**: Most tests require MySQL database setup:
46+
```bash
47+
# Start MySQL container (matches CI setup)
48+
docker run --name mysql_test -e MYSQL_ROOT_PASSWORD=Password12! -p 127.0.0.1:3306:3306 -d mysql:8.0.40
49+
50+
# Wait for MySQL to be ready (~30 seconds)
51+
while ! docker exec mysql_test mysql --protocol=tcp -h localhost -P 3306 -u root -pPassword12! -e 'select 1;' &>/dev/null; do
52+
echo "Waiting for MySQL..."
53+
sleep 2
54+
done
55+
echo "MySQL is ready!"
56+
```
57+
58+
### Running Tests (Validated Timings)
59+
- **Unit tests only**: `dotnet test test/EFCore.MySql.Tests -c Debug --no-build --logger "console;verbosity=minimal"` (takes ~3 seconds, 77 tests)
60+
- **Small functional test subset**: Takes ~8-9 seconds per test class
61+
- **Full test suites**: NEVER CANCEL - Can take 20-45 minutes. Set timeout to 60+ minutes.
62+
63+
**WARNING**: The full test suite includes hundreds of tests across multiple projects. Each functional/integration test requires database connections and can be slow. Plan accordingly.
64+
65+
### EF Core Tools
66+
- **Verify tools**: `dotnet ef --version` (should show version 10.0.0)
67+
- **Scaffolding**: `dotnet ef dbcontext scaffold "<connection-string>" "Pomelo.EntityFrameworkCore.MySql" --output-dir <dir> --context <ContextName> --force`
68+
- **Migration commands**: Available but require properly configured DbContext
69+
70+
### Integration Test Setup
71+
The integration tests require additional setup:
72+
```bash
73+
# Integration tests have setup scripts (PowerShell)
74+
./test/EFCore.MySql.IntegrationTests/scripts/rebuild.ps1
75+
```
76+
**NOTE**: Integration test setup takes ~45+ seconds and may have complex dependencies.
77+
78+
## Validation
79+
- **Always run unit tests** after making changes: `dotnet test test/EFCore.MySql.Tests` (~3 seconds)
80+
- **Test database connectivity** before running functional tests: Ensure MySQL container is running and accessible
81+
- **Never run full test suite** unless specifically needed - it takes 20-45+ minutes
82+
- **Build verification**: Always build both Debug and Release configurations to ensure compatibility
83+
84+
## Common Issues and Workarounds
85+
- **Package restore failures**: Default NuGet.config references unreachable MyGet sources. Use the clean config provided above.
86+
- **Package vulnerability warnings**: Treated as errors. Disable with `--property TreatWarningsAsErrors=false`
87+
- **Test failures without database**: Functional and integration tests will fail if MySQL is not running
88+
- **Network restrictions**: If external package sources are blocked, use `--ignore-failed-sources` with dotnet restore
89+
90+
## Repository Structure
91+
Key projects:
92+
- `src/EFCore.MySql/`: Main Entity Framework provider library
93+
- `src/EFCore.MySql.Json.Microsoft/`: Microsoft System.Text.Json support
94+
- `src/EFCore.MySql.Json.Newtonsoft/`: Newtonsoft.Json support
95+
- `src/EFCore.MySql.NTS/`: NetTopologySuite spatial support
96+
- `test/EFCore.MySql.Tests/`: Unit tests (77 tests, ~3 seconds)
97+
- `test/EFCore.MySql.FunctionalTests/`: Database integration tests
98+
- `test/EFCore.MySql.IntegrationTests/`: Full ASP.NET Core integration tests
99+
100+
## Key Commands Reference (Copy-Paste Ready)
101+
```bash
102+
# Complete setup from fresh clone
103+
export PATH="$HOME/.dotnet:$PATH"
104+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 10
105+
export PATH="$HOME/.dotnet:$PATH"
106+
107+
# Create clean NuGet config
108+
cat > /tmp/nuget.config << 'EOF'
109+
<?xml version="1.0" encoding="utf-8"?>
110+
<configuration>
111+
<packageSources>
112+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
113+
</packageSources>
114+
<config>
115+
<add key="disableNugetaudit" value="true" />
116+
</config>
117+
</configuration>
118+
EOF
119+
120+
# Install tools and restore packages
121+
dotnet tool restore
122+
dotnet restore --configfile /tmp/nuget.config --disable-parallel --no-cache --property WarningsAsErrors= --property TreatWarningsAsErrors=false
123+
124+
# Setup test configurations
125+
cp test/EFCore.MySql.FunctionalTests/config.json.example test/EFCore.MySql.FunctionalTests/config.json
126+
cp test/EFCore.MySql.IntegrationTests/config.json.example test/EFCore.MySql.IntegrationTests/config.json
127+
128+
# Build (NEVER CANCEL - set 15+ minute timeout)
129+
dotnet build -c Debug --no-restore
130+
dotnet build -c Release --no-restore
131+
132+
# Quick validation (unit tests only)
133+
dotnet test test/EFCore.MySql.Tests -c Debug --no-build --logger "console;verbosity=minimal"
134+
135+
# For database tests, setup MySQL first:
136+
docker run --name mysql_test -e MYSQL_ROOT_PASSWORD=Password12! -p 127.0.0.1:3306:3306 -d mysql:8.0.40
137+
```
138+
139+
Always use these exact commands for consistent results. Never skip the NuGet configuration step as it resolves critical network access issues.

.github/workflows/build.yml

Lines changed: 155 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,83 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
dbVersion:
27-
- 8.4.3-mysql
28-
- 8.0.40-mysql
29-
- 11.6.2-mariadb
30-
- 11.5.2-mariadb
31-
- 11.4.4-mariadb
32-
- 11.3.2-mariadb
33-
- 10.11.10-mariadb
34-
- 10.6.20-mariadb
35-
- 10.5.27-mariadb
36-
os:
37-
- ubuntu-latest
38-
- windows-latest
26+
include:
27+
# MySQL 9.5.x - Ubuntu only (Windows package not available yet)
28+
- dbVersion: 9.5.0-mysql
29+
os: ubuntu-latest
30+
# MySQL 9.x - Both platforms
31+
- dbVersion: 9.4.0-mysql
32+
os: ubuntu-latest
33+
- dbVersion: 9.4.0-mysql
34+
os: windows-latest
35+
- dbVersion: 9.3.0-mysql
36+
os: ubuntu-latest
37+
- dbVersion: 9.3.0-mysql
38+
os: windows-latest
39+
- dbVersion: 9.2.0-mysql
40+
os: ubuntu-latest
41+
- dbVersion: 9.2.0-mysql
42+
os: windows-latest
43+
- dbVersion: 9.1.0-mysql
44+
os: ubuntu-latest
45+
- dbVersion: 9.1.0-mysql
46+
os: windows-latest
47+
- dbVersion: 9.0.1-mysql
48+
os: ubuntu-latest
49+
- dbVersion: 9.0.1-mysql
50+
os: windows-latest
51+
# MySQL 8.x - Both platforms
52+
- dbVersion: 8.4.3-mysql
53+
os: ubuntu-latest
54+
- dbVersion: 8.4.3-mysql
55+
os: windows-latest
56+
- dbVersion: 8.0.40-mysql
57+
os: ubuntu-latest
58+
- dbVersion: 8.0.40-mysql
59+
os: windows-latest
60+
# MariaDB 11.8+ - Ubuntu only (Windows package not available yet)
61+
- dbVersion: 11.8.5-mariadb
62+
os: ubuntu-latest
63+
# MariaDB 11.7.x - Both platforms (different patch versions)
64+
- dbVersion: 11.7.2-mariadb
65+
os: ubuntu-latest
66+
- dbVersion: 11.7.1-mariadb
67+
os: windows-latest
68+
# MariaDB 11.x - Both platforms
69+
- dbVersion: 11.6.2-mariadb
70+
os: ubuntu-latest
71+
- dbVersion: 11.6.2-mariadb
72+
os: windows-latest
73+
- dbVersion: 11.5.2-mariadb
74+
os: ubuntu-latest
75+
- dbVersion: 11.5.2-mariadb
76+
os: windows-latest
77+
- dbVersion: 11.4.4-mariadb
78+
os: ubuntu-latest
79+
- dbVersion: 11.4.4-mariadb
80+
os: windows-latest
81+
- dbVersion: 11.3.2-mariadb
82+
os: ubuntu-latest
83+
- dbVersion: 11.3.2-mariadb
84+
os: windows-latest
85+
# MariaDB 10.x - Both platforms
86+
- dbVersion: 10.11.10-mariadb
87+
os: ubuntu-latest
88+
- dbVersion: 10.11.10-mariadb
89+
os: windows-latest
90+
- dbVersion: 10.6.20-mariadb
91+
os: ubuntu-latest
92+
- dbVersion: 10.6.20-mariadb
93+
os: windows-latest
94+
- dbVersion: 10.5.27-mariadb
95+
os: ubuntu-latest
96+
- dbVersion: 10.5.27-mariadb
97+
os: windows-latest
98+
# MariaDB 12.x - Ubuntu only (Windows packages not available yet)
99+
- dbVersion: 12.1.2-mariadb
100+
os: ubuntu-latest
101+
- dbVersion: 12.0.2-mariadb
102+
os: ubuntu-latest
39103
runs-on: ${{ matrix.os }}
40104
steps:
41105
- name: Checkout
@@ -104,6 +168,12 @@ jobs:
104168
with:
105169
path: ${{ env.windowsUserTempLocation }}\Pomelo.Chocolatey.${{ env.databaseServerType }}.Server
106170
key: database-windows-${{ env.databaseServerType }}-${{ env.databaseServerVersion }}-v3
171+
- name: Prepare certs & NuGet env
172+
if: ${{ env.os == 'linux' }}
173+
run: |
174+
sudo apt-get update
175+
sudo apt-get install -y ca-certificates
176+
echo "NUGET_CERT_REVOCATION_MODE=offline" >> $GITHUB_ENV
107177
- name: Install Database Server - Linux
108178
if: ${{ env.os == 'linux' }}
109179
shell: pwsh
@@ -213,6 +283,78 @@ jobs:
213283
shell: pwsh
214284
run: |
215285
dotnet --info
286+
- name: Fix MSB4276 - Create missing WorkloadAutoImportPropsLocator SDK
287+
shell: pwsh
288+
run: |
289+
$sdkPath = dotnet --info | Select-String "Base Path:\s+(.+)" | ForEach-Object { $_.Matches.Groups[1].Value.Trim() }
290+
$workloadSdkPath = Join-Path $sdkPath "Sdks/Microsoft.NET.SDK.WorkloadAutoImportPropsLocator"
291+
292+
if (-not (Test-Path $workloadSdkPath)) {
293+
Write-Host "Creating missing WorkloadAutoImportPropsLocator SDK at: $workloadSdkPath"
294+
New-Item -ItemType Directory -Path "$workloadSdkPath/Sdk" -Force | Out-Null
295+
296+
# Create Sdk.props
297+
$sdkPropsContent = @'
298+
<!--
299+
***********************************************************************************************
300+
Sdk.props
301+
302+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
303+
created a backup copy. Incorrect changes to this file will make it
304+
impossible to load or build your projects from the command-line or the IDE.
305+
306+
Copyright (c) .NET Foundation. All rights reserved.
307+
***********************************************************************************************
308+
-->
309+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
310+
</Project>
311+
'@
312+
$sdkPropsContent | Out-File -FilePath "$workloadSdkPath/Sdk/Sdk.props" -Encoding UTF8 -NoNewline
313+
314+
# Create Sdk.targets
315+
$sdkTargetsContent = @'
316+
<!--
317+
***********************************************************************************************
318+
Sdk.targets
319+
320+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
321+
created a backup copy. Incorrect changes to this file will make it
322+
impossible to load or build your projects from the command-line or the IDE.
323+
324+
Copyright (c) .NET Foundation. All rights reserved.
325+
***********************************************************************************************
326+
-->
327+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
328+
</Project>
329+
'@
330+
$sdkTargetsContent | Out-File -FilePath "$workloadSdkPath/Sdk/Sdk.targets" -Encoding UTF8 -NoNewline
331+
332+
# Create AutoImport.props
333+
$autoImportContent = @'
334+
<!--
335+
***********************************************************************************************
336+
AutoImport.props
337+
338+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
339+
created a backup copy. Incorrect changes to this file will make it
340+
impossible to load or build your projects from the command-line or the IDE.
341+
342+
This file is auto-imported by Microsoft.NET.Sdk.ImportWorkloads.props
343+
to import workload-specific props files.
344+
345+
Copyright (c) .NET Foundation. All rights reserved.
346+
***********************************************************************************************
347+
-->
348+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
349+
<!-- This file imports workload props. For now it's empty as no workloads require auto-import props. -->
350+
</Project>
351+
'@
352+
$autoImportContent | Out-File -FilePath "$workloadSdkPath/Sdk/AutoImport.props" -Encoding UTF8 -NoNewline
353+
354+
Write-Host "Successfully created WorkloadAutoImportPropsLocator SDK"
355+
} else {
356+
Write-Host "WorkloadAutoImportPropsLocator SDK already exists at: $workloadSdkPath"
357+
}
216358
- name: Install EF Core Tools
217359
shell: pwsh
218360
run: |

0 commit comments

Comments
 (0)