Skip to content

Commit ab85c7b

Browse files
committed
Added custom instructions
1 parent 702743d commit ab85c7b

11 files changed

+871
-5
lines changed

.github/copilot-instructions.md

Lines changed: 511 additions & 0 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
**/bin/**
44
**/obj/**
55
**/packages/**
6+
.serena/cache/**
7+
.local-memory/**
68

7-
*\.sln\.DotSettings\.user
9+
*\.sln\.DotSettings\.user
10+
.claude/settings.local.json
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code Style and Conventions
2+
- C# 13.0, .NET 8.0/9.0
3+
- Nullable reference types enabled
4+
- Implicit usings enabled
5+
- Centralized package management via Directory.Packages.props
6+
- XML documentation files generated
7+
- Follows standard .NET naming conventions
8+
- Tests use xUnit
9+
- Benchmarking uses BenchmarkDotNet
10+
- All projects use the root namespace `Thinktecture`
11+
- Warnings CA1303, MSB3884 suppressed
12+
- Authors and copyright set in Directory.Build.props
13+
- Use of PropertyGroup for shared MSBuild properties
14+
- Use of ItemGroup for shared package references
15+
- All code should be documented and follow .NET best practices
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Project Purpose
2+
Thinktecture.EntityFrameworkCore is a set of libraries that extend Entity Framework Core with additional features for performance, convenience, and integration testing. It provides enhancements for bulk operations, temp-tables, window functions, table hints, and more, targeting SQL Server and SQLite. The project is maintained by Pawel Gerr and is available on both Azure DevOps and GitHub.
3+
4+
# Tech Stack
5+
- .NET 8.0 and 9.0 (C#)
6+
- Entity Framework Core (EF Core)
7+
- SQL Server, SQLite
8+
- Azure Pipelines for CI/CD
9+
- PowerShell for CI scripting
10+
- NuGet for package management
11+
- xUnit for testing
12+
- BenchmarkDotNet for performance benchmarks
13+
14+
# Codebase Structure
15+
- `src/`: Main library source code, organized by feature and database provider (BulkOperations, Relational, Sqlite, SqlServer, Testing)
16+
- `tests/`: Unit and integration tests for each main library
17+
- `samples/`: Sample and benchmark projects for usage demonstration
18+
- `ci/`: CI scripts (PowerShell)
19+
- Solution and build configuration files at the root
20+
21+
# Key Components
22+
- Bulk operations and performance features (BulkOperations)
23+
- Relational and provider-specific extensions (Relational, Sqlite, SqlServer)
24+
- Testing utilities and helpers
25+
- Sample and benchmark projects for both SQL Server and SQLite
26+
27+
# Entry Points
28+
- Libraries are consumed as NuGet packages
29+
- Sample and benchmark projects have `Program.cs` as entry points
30+
31+
# Notable Guidelines
32+
- Follows .NET and C# conventions (nullable enabled, implicit usings, LangVersion 13.0)
33+
- Centralized package management
34+
- Documentation and samples provided for all major features
35+
36+
See additional memories for commands, style, and task completion guidelines.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Code Style and Conventions
2+
- Namespaces start with `Thinktecture` and match folder structure
3+
- Nullable reference types enabled; use explicit null checks with `ArgumentNullException.ThrowIfNull(...)`
4+
- Async-first: provide async APIs with `CancellationToken` for I/O operations; avoid sync-over-async
5+
- Minimal public surface: prefer `internal` unless cross-package usage is needed
6+
- File-scoped namespaces, expression-bodied members where appropriate
7+
- Immutability: use `readonly` fields/structs where intended; prefer `record` for value-like objects
8+
- Query composition: keep operations server-evaluable; avoid client evaluation; prefer `IQueryable` over early `ToList()`
9+
- SQL safety: never concatenate raw SQL; use `FromSqlInterpolated` or helpers
10+
- Read-only queries: use `AsNoTracking()` unless state tracking is needed
11+
- Transactions: use EF Core `IDbContextTransaction`/`ExecutionStrategy` patterns
12+
- Provider specifics: SQL Server (table hints, temp tables, bulk ops), SQLite (conditional code for limitations)
13+
- XML documentation required for all public APIs
14+
- Tests: xUnit + AwesomeAssertions + NSubstitute + Serilog XUnit sink
15+
- Test naming: `MethodName_Should_DoSomething_When_Condition`
16+
- Test structure mirrors source structure
17+
- Deterministic tests: avoid time-based operations, use predictable data
18+
- Use `CollectExecutedCommands()` to verify SQL in tests
19+
- Centralized package versions in `Directory.Packages.props`
20+
- No inline package versions in `.csproj`
21+
- Build and test for both `net8.0` and `net9.0`
22+
- No new analyzer warnings or violations
23+
- Add XML docs and examples for public APIs
24+
- Use file-scoped namespaces and expression-bodied members where it improves clarity
25+
- Use guard clauses for argument validation
26+
- Use async/await and propagate `CancellationToken`
27+
- Throw appropriate exceptions for error handling
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Suggested Commands for Development
2+
3+
## Build
4+
- `dotnet build` — Builds the solution (Thinktecture.EntityFrameworkCore.slnx)
5+
6+
## Test
7+
- `dotnet test tests/**/*.csproj` — Runs all tests
8+
9+
## Pack
10+
- `dotnet pack -c Release` — Creates NuGet packages
11+
12+
## Run Samples/Benchmarks
13+
- `dotnet run --project samples/Thinktecture.EntityFrameworkCore.SqlServer.Samples`
14+
- `dotnet run --project samples/Thinktecture.EntityFrameworkCore.Sqlite.Samples`
15+
- `dotnet run --project samples/Thinktecture.EntityFrameworkCore.Benchmarks`
16+
17+
## CI/CD
18+
- Azure Pipelines: defined in `azure-pipelines.yml`
19+
- PowerShell CI script: `ci/ci.ps1`
20+
21+
## Version Suffix (for releases)
22+
- Run PowerShell: `. ./ci/ci.ps1; Set-VersionSuffixOnTag <dir> <branch>`
23+
24+
## Utilities (Windows)
25+
- Use PowerShell for scripting
26+
- Standard git commands for version control
27+
28+
See Readme.md and azure-pipelines.yml for more details.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# What to Do When a Task is Completed
2+
3+
1. Ensure all code builds and passes tests on both `net8.0` and `net9.0`.
4+
2. Check for and resolve any analyzer warnings or code style violations.
5+
3. Ensure new/changed code follows repository conventions (see style_and_conventions.md).
6+
4. Add or update XML documentation for any public APIs.
7+
5. If the change is performance-sensitive, add or update benchmarks in `samples/Thinktecture.EntityFrameworkCore.Benchmarks`.
8+
6. If the change is user-facing, update samples and documentation as needed.
9+
7. For new features or bug fixes:
10+
- Add/extend tests in `tests/**` (unit first, integration if needed)
11+
- Use `CollectExecutedCommands()` in tests to verify SQL if relevant
12+
- Ensure provider-specific code is handled for both SQL Server and SQLite
13+
8. If dependencies were added, update `Directory.Packages.props` and reference in `.csproj` (no inline versions).
14+
9. If the change affects CI/CD, update `azure-pipelines.yml` or scripts in `ci/`.
15+
10. Commit and push changes, then create a pull request with a clear description and scope.
16+
11. Ensure PR passes all CI checks before merging.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Task Completion Guidelines
2+
- Ensure all code builds and tests pass (`dotnet build`, `dotnet test`)
3+
- Update documentation if new features or changes are introduced
4+
- If releasing, ensure version suffix is set for tags
5+
- Run benchmarks if performance is affected
6+
- Follow code style and conventions
7+
- Update samples if APIs change
8+
- Commit and push changes with clear messages
9+
- For CI/CD, verify Azure Pipelines status
10+
- For new features, add or update tests in the appropriate `tests/` project
11+
- For bug fixes, add regression tests if possible
12+
- For new features or changes, update Readme.md and relevant wiki pages

.serena/project.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
2+
# * For C, use cpp
3+
# * For JavaScript, use typescript
4+
# Special requirements:
5+
# * csharp: Requires the presence of a .sln file in the project folder.
6+
language: csharp
7+
8+
# whether to use the project's gitignore file to ignore files
9+
# Added on 2025-04-07
10+
ignore_all_files_in_gitignore: true
11+
# list of additional paths to ignore
12+
# same syntax as gitignore, so you can use * and **
13+
# Was previously called `ignored_dirs`, please update your config if you are using that.
14+
# Added (renamed)on 2025-04-07
15+
ignored_paths: []
16+
17+
# whether the project is in read-only mode
18+
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
19+
# Added on 2025-04-18
20+
read_only: false
21+
22+
23+
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
24+
# Below is the complete list of tools for convenience.
25+
# To make sure you have the latest list of tools, and to view their descriptions,
26+
# execute `uv run scripts/print_tool_overview.py`.
27+
#
28+
# * `activate_project`: Activates a project by name.
29+
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
30+
# * `create_text_file`: Creates/overwrites a file in the project directory.
31+
# * `delete_lines`: Deletes a range of lines within a file.
32+
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
33+
# * `execute_shell_command`: Executes a shell command.
34+
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
35+
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
36+
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
37+
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
38+
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
39+
# * `initial_instructions`: Gets the initial instructions for the current project.
40+
# Should only be used in settings where the system prompt cannot be set,
41+
# e.g. in clients you have no control over, like Claude Desktop.
42+
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
43+
# * `insert_at_line`: Inserts content at a given line in a file.
44+
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
45+
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
46+
# * `list_memories`: Lists memories in Serena's project-specific memory store.
47+
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
48+
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
49+
# * `read_file`: Reads a file within the project directory.
50+
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
51+
# * `remove_project`: Removes a project from the Serena configuration.
52+
# * `replace_lines`: Replaces a range of lines within a file with new content.
53+
# * `replace_symbol_body`: Replaces the full definition of a symbol.
54+
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
55+
# * `search_for_pattern`: Performs a search for a pattern in the project.
56+
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
57+
# * `switch_modes`: Activates modes by providing a list of their names
58+
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
59+
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
60+
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
61+
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
62+
excluded_tools: []
63+
64+
# initial prompt for the project. It will always be given to the LLM upon activating the project
65+
# (contrary to the memories, which are loaded on demand).
66+
initial_prompt: ""
67+
68+
project_name: "Thinktecture.EntityFrameworkCore"

CLAUDE.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Essential Development Commands
6+
7+
### Building the Solution
8+
```powershell
9+
dotnet restore
10+
dotnet build -c Release
11+
```
12+
13+
### Running Tests
14+
```powershell
15+
dotnet test -c Release --no-build
16+
```
17+
18+
### Running a Single Test Project
19+
```powershell
20+
dotnet test tests/Thinktecture.EntityFrameworkCore.SqlServer.Tests/ -c Release
21+
```
22+
23+
## Architecture Overview
24+
25+
This repository extends Entity Framework Core with performance enhancements and testing utilities across multiple database providers.
26+
27+
### Core Package Structure
28+
29+
**Runtime Packages (`src/`)**:
30+
- `Thinktecture.EntityFrameworkCore.Relational` - Base abstractions and shared functionality
31+
- `Thinktecture.EntityFrameworkCore.BulkOperations` - Multi-provider bulk operations
32+
- `Thinktecture.EntityFrameworkCore.SqlServer` - SQL Server specific features
33+
- `Thinktecture.EntityFrameworkCore.Sqlite` - SQLite specific features
34+
- `Thinktecture.EntityFrameworkCore.Testing` - Base testing infrastructure
35+
- `Thinktecture.EntityFrameworkCore.SqlServer.Testing` - SQL Server test helpers
36+
- `Thinktecture.EntityFrameworkCore.Sqlite.Testing` - SQLite test helpers
37+
38+
**Test Structure (`tests/`)**:
39+
- Tests mirror the `src/` structure with `.Tests` suffix
40+
- `TestHelpers` package provides shared test utilities
41+
42+
### Key Architectural Patterns
43+
44+
**Bulk Operations Architecture**:
45+
- Provider-agnostic interfaces (`IBulkInsertExecutor`, `IBulkUpdateExecutor`, etc.)
46+
- SQL Server implementation uses `SqlBulkCopy` for inserts and MERGE statements for updates
47+
- Context factories manage connection lifecycle and transaction handling
48+
- Strongly-typed options classes inherit from base interfaces
49+
50+
**Temp Tables Architecture**:
51+
- `ITempTableCreator` creates temp tables with `ITempTableReference` for lifecycle management
52+
- `ITempTableQuery<T>` wraps `IQueryable<T>` with automatic cleanup via `IAsyncDisposable`
53+
- Integration with bulk operations via `ITempTableBulkInsertExecutor`
54+
55+
**Multi-Provider Support**:
56+
- Shared interfaces in BulkOperations with provider-specific implementations
57+
- SQL Server: Table hints, temp tables, window functions, tenant database support
58+
- SQLite: Simplified bulk operations, window functions, limitation handling
59+
60+
## Testing Infrastructure
61+
62+
### SQL Server Integration Tests
63+
- Base class: `IntegrationTestsBase`
64+
- Mark tests with `[Collection("SqlServerTests")]` for proper isolation
65+
- Use `SqlServerFixture` for shared connections
66+
- Capture SQL with `CollectExecutedCommands()` to verify generated queries
67+
68+
### SQLite Integration Tests
69+
- Base class: `SqliteDbContextIntegrationTests<T>`
70+
- Use `DbContextProviderFactoryFixture` for database lifecycle management
71+
- Less isolation requirements compared to SQL Server tests
72+
73+
### Test Patterns
74+
- xUnit + AwesomeAssertions + NSubstitute + Serilog XUnit sink
75+
- Naming: `MethodName_Should_DoSomething_When_Condition`
76+
- Use `ArrangeDbContext`, `ActDbContext`, `AssertDbContext` for different test phases
77+
- Results written to `test-results/<TargetFramework>/`
78+
79+
## Development Workflows
80+
81+
### Feature Development (Test-First Approach)
82+
1. **Understand scope**: Identify affected packages in `src/**` and corresponding tests in `tests/**`
83+
2. **Write failing tests first**: Create unit tests in `tests/<Package>.Tests/**` folder
84+
3. **Minimal public surface**: Keep APIs `internal` unless cross-package usage is needed
85+
4. **Server-evaluable queries**: Ensure EF Core operations stay on the server side
86+
5. **Use appropriate test base**: `IntegrationTestsBase` for SQL Server, `SqliteDbContextIntegrationTests<T>` for SQLite
87+
6. **Verify SQL generation**: Use `CollectExecutedCommands()` to validate generated SQL
88+
89+
### Bug Fix Workflow
90+
1. **Reproduce first**: Create a failing test demonstrating the bug
91+
2. **Minimal fix**: Implement the smallest change to pass the test
92+
3. **Multi-TFM validation**: Test on both `net8.0` and `net9.0`
93+
94+
## Key Development Guidelines
95+
96+
### EF Core Specifics
97+
- Keep operations server-evaluable; avoid client evaluation; prefer `IQueryable` over early `ToList()`
98+
- Never concatenate raw SQL; use `FromSqlInterpolated` or existing parameterized helpers
99+
- Use `AsNoTracking()` for read-only queries unless state tracking is needed
100+
- Always provide async APIs with `CancellationToken` for I/O operations; avoid sync-over-async
101+
- Use EF Core `IDbContextTransaction`/`ExecutionStrategy` patterns for transactions
102+
103+
### Code Conventions
104+
- Target frameworks: `net8.0` and `net9.0`
105+
- C# 13.0 with nullable reference types enabled, implicit usings enabled
106+
- File-scoped namespaces starting with `Thinktecture` and match folder structure
107+
- Default to `internal` visibility unless cross-package usage is needed
108+
- Use explicit null checks with `ArgumentNullException.ThrowIfNull()`
109+
- Expression-bodied members where appropriate; prefer `record` for value-like objects
110+
111+
### Package Management
112+
- All package versions centralized in `Directory.Packages.props`
113+
- Reference packages from `.csproj` files without version numbers
114+
- EF Core 9.x is the current target version (Microsoft.EntityFrameworkCore.*: 9.0.8)
115+
116+
### Provider-Specific Considerations
117+
- SQL Server: Leverage table hints, temp tables, bulk operations via existing abstractions
118+
- SQLite: Account for concurrency limitations, DDL locks, missing server features
119+
- Add conditional code paths only when necessary; maintain consistent API surface where possible
120+
121+
### Essential Patterns
122+
```csharp
123+
// Proper async method signature
124+
public async Task<Result> ProcessAsync(CancellationToken cancellationToken = default)
125+
{
126+
ArgumentNullException.ThrowIfNull(parameter);
127+
var data = await GetDataAsync(cancellationToken);
128+
return ProcessData(data);
129+
}
130+
131+
// Bulk operations usage
132+
await ActDbContext.BulkInsertAsync(entities);
133+
await using var tempTable = await ActDbContext.BulkInsertIntoTempTableAsync(values);
134+
135+
// Table hints (SQL Server)
136+
query.WithTableHints(SqlServerTableHint.NoLock)
137+
138+
// Window functions
139+
EF.Functions.WindowFunction(function, arg, EF.Functions.PartitionBy(...), EF.Functions.OrderBy(...))
140+
```
141+
142+
## Important Files to Know
143+
144+
- `Thinktecture.EntityFrameworkCore.slnx` - Main solution file
145+
- `Directory.Packages.props` - Centralized package version management
146+
- `Directory.Build.props` - Shared MSBuild properties
147+
- `.github/copilot-instructions.md` - Comprehensive development guidelines
148+
- Test results are written to `test-results/<TargetFramework>/`

0 commit comments

Comments
 (0)