Skip to content

Commit 0682fc2

Browse files
authored
Merge pull request #81 from WeihanLi/copilot/fix-74
Add comprehensive documentation with usage guides and examples for all features
2 parents a77f93b + 6377710 commit 0682fc2

File tree

4 files changed

+2755
-61
lines changed

4 files changed

+2755
-61
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 130 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,94 @@
1010

1111
## Intro
1212

13-
[EntityFrameworkCore](https://github.com/dotnet/efcore) extensions
13+
[EntityFrameworkCore](https://github.com/dotnet/efcore) extensions that provide a comprehensive set of tools and patterns to enhance your Entity Framework Core development experience.
14+
15+
WeihanLi.EntityFramework offers:
16+
17+
- **Repository Pattern** - Clean abstraction layer for data access
18+
- **Unit of Work Pattern** - Transaction management across multiple repositories
19+
- **Automatic Auditing** - Track all entity changes with flexible storage options
20+
- **Auto-Update Features** - Automatic handling of CreatedAt/UpdatedAt timestamps and user tracking
21+
- **Soft Delete** - Mark entities as deleted without physical removal
22+
- **Database Extensions** - Convenient methods for bulk operations and queries
23+
- **Database Functions** - SQL Server JSON operations and more
24+
25+
## Quick Start
26+
27+
### 1. Installation
28+
29+
```bash
30+
dotnet add package WeihanLi.EntityFramework
31+
```
32+
33+
### 2. Basic Setup
34+
35+
```csharp
36+
// Program.cs
37+
var builder = WebApplication.CreateBuilder(args);
38+
39+
// Add DbContext
40+
builder.Services.AddDbContext<MyDbContext>(options =>
41+
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
42+
43+
// Add WeihanLi.EntityFramework services
44+
builder.Services.AddEFRepository();
45+
builder.Services.AddEFAutoUpdateInterceptor();
46+
builder.Services.AddEFAutoAudit(auditBuilder =>
47+
{
48+
auditBuilder.WithUserIdProvider<HttpContextUserIdProvider>()
49+
.WithStore<AuditDatabaseStore>();
50+
});
51+
52+
var app = builder.Build();
53+
```
54+
55+
### 3. Define Your Entities
56+
57+
```csharp
58+
public class Product : IEntityWithCreatedUpdatedAt, ISoftDeleteEntityWithDeleted
59+
{
60+
public int Id { get; set; }
61+
public string Name { get; set; } = string.Empty;
62+
public decimal Price { get; set; }
63+
64+
// Auto-update properties
65+
public DateTimeOffset CreatedAt { get; set; }
66+
public DateTimeOffset UpdatedAt { get; set; }
67+
68+
// Soft delete property
69+
public bool IsDeleted { get; set; }
70+
}
71+
```
72+
73+
### 4. Use Repository Pattern
74+
75+
```csharp
76+
public class ProductService
77+
{
78+
private readonly IEFRepository<MyDbContext, Product> _repository;
79+
80+
public ProductService(IEFRepository<MyDbContext, Product> repository)
81+
{
82+
_repository = repository;
83+
}
84+
85+
public async Task<Product> CreateProductAsync(string name, decimal price)
86+
{
87+
var product = new Product { Name = name, Price = price };
88+
return await _repository.InsertAsync(product);
89+
// CreatedAt/UpdatedAt automatically set, audit record created
90+
}
91+
92+
public async Task<List<Product>> GetActiveProductsAsync()
93+
{
94+
return await _repository.GetListAsync(
95+
queryBuilder => queryBuilder.WithPredict(p => p.Price > 0)
96+
);
97+
// Soft deleted products automatically filtered out
98+
}
99+
}
100+
```
14101

15102
## Package Release Notes
16103

@@ -33,36 +120,58 @@ See Releases/PRs for details
33120
34121
## Features
35122

36-
- Repository
37-
38-
- `EFRepository`
39-
- `EFRepositoryGenerator`
123+
### πŸ—οΈ Repository Pattern
124+
- `IEFRepository<TDbContext, TEntity>` - Generic repository interface
125+
- `EFRepository` - Full-featured repository implementation
126+
- `EFRepositoryGenerator` - Dynamic repository creation
127+
- **Query Builder** - Fluent API for complex queries
128+
- **Bulk Operations** - Efficient batch updates and deletes
40129

41-
- UoW
42-
43-
- `EFUnitOfWork`
130+
### πŸ”„ Unit of Work Pattern
131+
- `IEFUnitOfWork<TDbContext>` - Transaction management
132+
- **Multi-Repository Transactions** - Coordinate changes across entities
133+
- **Rollback Support** - Automatic error handling
44134

45-
- DbFunctions
46-
47-
- `JsonValue` implement `JSON_VALUE` for SqlServer 2016 and above
135+
### πŸ“‹ Comprehensive Auditing
136+
- **Automatic Change Tracking** - Monitor all entity modifications
137+
- **Flexible Storage** - Database, file, console, or custom stores
138+
- **Property Enrichment** - Add custom metadata to audit records
139+
- **User Tracking** - Capture who made changes
140+
- **Configurable Filtering** - Include/exclude entities and properties
48141

49-
- Audit
142+
### ⚑ Auto-Update Features
143+
- **Timestamp Management** - Automatic CreatedAt/UpdatedAt handling
144+
- **User Tracking** - Automatic CreatedBy/UpdatedBy population
145+
- **Soft Delete** - Mark entities as deleted without removal
146+
- **Custom Auto-Update** - Define your own auto-update rules
50147

51-
- Auto auditing for entity changes
52-
53-
- AutoUpdate
148+
### πŸ”§ Database Extensions
149+
- **Column Updates** - Update specific columns only
150+
- **Bulk Operations** - Efficient mass updates
151+
- **Query Helpers** - Get table/column names, check database type
152+
- **Paging Support** - Built-in pagination for large datasets
54153

55-
- Soft delete for the specific entity
56-
- Auto update CreatedAt/UpdatedAt/CreatedBy/UpdatedBy
154+
### πŸ—„οΈ Database Functions
155+
- **JSON Support** - `JSON_VALUE` for SQL Server 2016+
156+
- **SQL Server Functions** - Enhanced querying capabilities
57157

58-
- Extensions
158+
## Documentation
59159

60-
- Update specific column(s) `Update`
61-
- Update without specific column(s) `UpdateWithout`
160+
πŸš€ **[Getting Started Guide](docs/GettingStarted.md)** - Step-by-step setup instructions for new users
161+
162+
πŸ“– **[Complete Usage Guide](docs/Usage.md)** - Comprehensive documentation with examples for all features
163+
164+
⚑ **[Advanced Features Guide](docs/AdvancedFeatures.md)** - Custom interceptors, performance optimization, and integration patterns
165+
166+
πŸ“‹ **[Release Notes](docs/ReleaseNotes.md)** - Version history and breaking changes
167+
168+
πŸ”§ **[Sample Project](samples/WeihanLi.EntityFramework.Sample/)** - Working examples and demonstrations
62169

63170
## Support
64171

65-
Feel free to try and [create issues](https://github.com/WeihanLi/WeihanLi.EntityFramework/issues/new) if you have any questions or integration issues
172+
πŸ’‘ **Questions?** Check out the [Usage Guide](docs/Usage.md) for detailed examples
173+
174+
πŸ› **Found a bug or need help?** Feel free to [create an issue](https://github.com/WeihanLi/WeihanLi.EntityFramework/issues/new) with reproduction steps
66175

67176
## Usage
68177

0 commit comments

Comments
Β (0)