Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
92bb337
feat: update dotnet 10
WeihanLi Mar 21, 2025
5456cbb
feat: update CI dotnet sdk to dotnet 10
WeihanLi Mar 21, 2025
9958636
refactor: fix generator reference and warnings
WeihanLi Mar 21, 2025
8bfb585
refactor: use xunit v3
WeihanLi Mar 21, 2025
08e6d61
Automated dotnet-format update from commit 8bfb585e0648fcd2baee3d8447…
WeihanLi Mar 21, 2025
fb9e01a
Update version.props
WeihanLi Mar 21, 2025
b726768
Update WeihanLi.EntityFramework.Test.csproj
WeihanLi Mar 24, 2025
0f3a263
Add usage documentation
WeihanLi Apr 2, 2025
e82a643
Update Directory.Build.props
WeihanLi Apr 11, 2025
b6df422
Merge pull request #76 from WeihanLi/add-usage-documentation
WeihanLi Apr 11, 2025
0b3b76e
Update Directory.Build.props
WeihanLi Apr 15, 2025
a8a9c25
Update Directory.Build.props
WeihanLi Jun 11, 2025
1a60a2e
Update Directory.Build.props
WeihanLi Jun 17, 2025
3c04279
feat: bump dependencies
WeihanLi Jul 15, 2025
d70cc97
feat: use slnx
WeihanLi Jul 25, 2025
6f46a3a
feat: support ignore named query filter
WeihanLi Aug 2, 2025
92cce93
Automated dotnet-format update from commit 6f46a3a7bee88972be7ade89dd…
WeihanLi Aug 2, 2025
b5d6d08
update sample
WeihanLi Aug 2, 2025
2cbfc91
Merge branch 'dev' of https://github.com/WeihanLi/WeihanLi.EntityFram…
WeihanLi Aug 2, 2025
f0156ca
Automated dotnet-format update from commit 2cbfc919e7af0ec09019b96fb6…
WeihanLi Aug 2, 2025
dd9d97c
feat: bump dependencies
WeihanLi Aug 2, 2025
a77f93b
Merge branch 'dev' of https://github.com/WeihanLi/WeihanLi.EntityFram…
WeihanLi Aug 2, 2025
2e557b3
Initial plan
Copilot Aug 2, 2025
b636944
Add comprehensive documentation with usage guide, getting started, an…
Copilot Aug 2, 2025
00016fe
Finalize documentation with navigation links and complete structure
Copilot Aug 2, 2025
c5e99b8
Remove discussion reference from README as discussions are not enabled
Copilot Aug 2, 2025
6377710
Remove non-existent property value formatter from audit documentation
Copilot Aug 2, 2025
0682fc2
Merge pull request #81 from WeihanLi/copilot/fix-74
WeihanLi Aug 2, 2025
e105b89
feat: bump dependencies
WeihanLi Aug 16, 2025
115ec84
feat: bump xunit dependency
WeihanLi Aug 16, 2025
d2980bf
build: simplify build scripts
WeihanLi Aug 16, 2025
2768a06
build: remove prerelease flag for dotnet-exec tool
WeihanLi Aug 19, 2025
0b1eecd
Automated dotnet-format update from commit 2768a0640539b6826c424ab41d…
WeihanLi Aug 19, 2025
7608160
Update CommonVersion and EFVersion in build props
WeihanLi Sep 11, 2025
0e9b9cc
upgrade dependencies
WeihanLi Nov 11, 2025
5e90ca0
bump dependencies
WeihanLi Nov 12, 2025
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CodeSpace",
"image": "mcr.microsoft.com/dotnet/sdk:8.0",
"image": "mcr.microsoft.com/dotnet/sdk:10.0-preview",
// Install needed extensions
"extensions": [
"ms-dotnettools.csharp",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x
- name: dotnet info
run: dotnet --info
- name: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x
- name: build
run: dotnet build
- name: format
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x
- name: Build
shell: pwsh
run: .\build.ps1 --stable=true
Expand Down
7 changes: 3 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<Import Project="./build/version.props" />

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CommonVersion>1.0.75</CommonVersion>
<EFVersion>9.0.3</EFVersion>

<CommonVersion>1.0.84</CommonVersion>
<EFVersion>10.0.0</EFVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
155 changes: 134 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,94 @@

## Intro

[EntityFrameworkCore](https://github.com/dotnet/efcore) extensions
[EntityFrameworkCore](https://github.com/dotnet/efcore) extensions that provide a comprehensive set of tools and patterns to enhance your Entity Framework Core development experience.

WeihanLi.EntityFramework offers:

- **Repository Pattern** - Clean abstraction layer for data access
- **Unit of Work Pattern** - Transaction management across multiple repositories
- **Automatic Auditing** - Track all entity changes with flexible storage options
- **Auto-Update Features** - Automatic handling of CreatedAt/UpdatedAt timestamps and user tracking
- **Soft Delete** - Mark entities as deleted without physical removal
- **Database Extensions** - Convenient methods for bulk operations and queries
- **Database Functions** - SQL Server JSON operations and more

## Quick Start

### 1. Installation

```bash
dotnet add package WeihanLi.EntityFramework
```

### 2. Basic Setup

```csharp
// Program.cs
var builder = WebApplication.CreateBuilder(args);

// Add DbContext
builder.Services.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

// Add WeihanLi.EntityFramework services
builder.Services.AddEFRepository();
builder.Services.AddEFAutoUpdateInterceptor();
builder.Services.AddEFAutoAudit(auditBuilder =>
{
auditBuilder.WithUserIdProvider<HttpContextUserIdProvider>()
.WithStore<AuditDatabaseStore>();
});

var app = builder.Build();
```

### 3. Define Your Entities

```csharp
public class Product : IEntityWithCreatedUpdatedAt, ISoftDeleteEntityWithDeleted
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }

// Auto-update properties
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }

// Soft delete property
public bool IsDeleted { get; set; }
}
```

### 4. Use Repository Pattern

```csharp
public class ProductService
{
private readonly IEFRepository<MyDbContext, Product> _repository;

public ProductService(IEFRepository<MyDbContext, Product> repository)
{
_repository = repository;
}

public async Task<Product> CreateProductAsync(string name, decimal price)
{
var product = new Product { Name = name, Price = price };
return await _repository.InsertAsync(product);
// CreatedAt/UpdatedAt automatically set, audit record created
}

public async Task<List<Product>> GetActiveProductsAsync()
{
return await _repository.GetListAsync(
queryBuilder => queryBuilder.WithPredict(p => p.Price > 0)
);
// Soft deleted products automatically filtered out
}
}
```

## Package Release Notes

Expand All @@ -33,33 +120,59 @@ See Releases/PRs for details

## Features

- Repository

- `EFRepository`
- `EFRepositoryGenerator`
### 🏗️ Repository Pattern
- `IEFRepository<TDbContext, TEntity>` - Generic repository interface
- `EFRepository` - Full-featured repository implementation
- `EFRepositoryGenerator` - Dynamic repository creation
- **Query Builder** - Fluent API for complex queries
- **Bulk Operations** - Efficient batch updates and deletes

- UoW

- `EFUnitOfWork`
### 🔄 Unit of Work Pattern
- `IEFUnitOfWork<TDbContext>` - Transaction management
- **Multi-Repository Transactions** - Coordinate changes across entities
- **Rollback Support** - Automatic error handling

- DbFunctions

- `JsonValue` implement `JSON_VALUE` for SqlServer 2016 and above
### 📋 Comprehensive Auditing
- **Automatic Change Tracking** - Monitor all entity modifications
- **Flexible Storage** - Database, file, console, or custom stores
- **Property Enrichment** - Add custom metadata to audit records
- **User Tracking** - Capture who made changes
- **Configurable Filtering** - Include/exclude entities and properties

- Audit
### ⚡ Auto-Update Features
- **Timestamp Management** - Automatic CreatedAt/UpdatedAt handling
- **User Tracking** - Automatic CreatedBy/UpdatedBy population
- **Soft Delete** - Mark entities as deleted without removal
- **Custom Auto-Update** - Define your own auto-update rules

- Auto auditing for entity changes

- AutoUpdate
### 🔧 Database Extensions
- **Column Updates** - Update specific columns only
- **Bulk Operations** - Efficient mass updates
- **Query Helpers** - Get table/column names, check database type
- **Paging Support** - Built-in pagination for large datasets

- Soft delete for the specific entity
- Auto update CreatedAt/UpdatedAt/CreatedBy/UpdatedBy
### 🗄️ Database Functions
- **JSON Support** - `JSON_VALUE` for SQL Server 2016+
- **SQL Server Functions** - Enhanced querying capabilities

- Extensions
## Documentation

- Update specific column(s) `Update`
- Update without specific column(s) `UpdateWithout`
🚀 **[Getting Started Guide](docs/GettingStarted.md)** - Step-by-step setup instructions for new users

📖 **[Complete Usage Guide](docs/Usage.md)** - Comprehensive documentation with examples for all features

⚡ **[Advanced Features Guide](docs/AdvancedFeatures.md)** - Custom interceptors, performance optimization, and integration patterns

📋 **[Release Notes](docs/ReleaseNotes.md)** - Version history and breaking changes

🔧 **[Sample Project](samples/WeihanLi.EntityFramework.Sample/)** - Working examples and demonstrations

## Support

Feel free to try and [create issues](https://github.com/WeihanLi/WeihanLi.EntityFramework/issues/new) if you have any questions or integration issues
💡 **Questions?** Check out the [Usage Guide](docs/Usage.md) for detailed examples

🐛 **Found a bug or need help?** Feel free to [create an issue](https://github.com/WeihanLi/WeihanLi.EntityFramework/issues/new) with reproduction steps

## Usage

For detailed usage instructions, please refer to the [Usage Documentation](docs/Usage.md).
91 changes: 0 additions & 91 deletions WeihanLi.EntityFramework.sln

This file was deleted.

12 changes: 12 additions & 0 deletions WeihanLi.EntityFramework.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Solution>
<Folder Name="/samples/">
<Project Path="samples/WeihanLi.EntityFramework.Sample/WeihanLi.EntityFramework.Sample.csproj" />
</Folder>
<Folder Name="/src/">
<Project Path="src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj" />
<Project Path="src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj" />
</Folder>
</Solution>
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps:
displayName: 'Use .NET sdk'
inputs:
packageType: sdk
version: 9.0.x
version: 10.0.x
includePreviewVersions: true

- script: dotnet --info
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[string]$SCRIPT = '.\build\build.cs'

# Install dotnet tool
dotnet tool update --global dotnet-execute
dotnet tool install --global dotnet-execute

Write-Host "dotnet-exec $SCRIPT --args $ARGS" -ForegroundColor GREEN

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SCRIPT='./build/build.cs'

# Install tool
dotnet tool update --global dotnet-execute
dotnet tool install --global dotnet-execute
export PATH="$PATH:$HOME/.dotnet/tools"

echo "dotnet-exec $SCRIPT --args=$@"
Expand Down
Loading
Loading