Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
151 changes: 130 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,36 +120,58 @@ 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

Expand Down
Loading
Loading