EntityFrameworkCore 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
dotnet add package WeihanLi.EntityFramework
// 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();
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; }
}
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
}
}
See Releases/PRs for details
- Releases: https://github.com/WeihanLi/WeihanLi.EntityFramework/releases
- PRs: https://github.com/WeihanLi/WeihanLi.EntityFramework/pulls?q=is%3Apr+is%3Aclosed+is%3Amerged+base%3Amaster
Package Versions
For EF 8 and above, use 8.x or above major-version matched versions
For EF 7, use 3.x
For EF Core 5/6, use 2.x
For EF Core 3.x, use 1.5.0 above, and 2.0.0 below
For EF Core 2.x , use 1.4.x and below
IEFRepository<TDbContext, TEntity>
- Generic repository interfaceEFRepository
- Full-featured repository implementationEFRepositoryGenerator
- Dynamic repository creation- Query Builder - Fluent API for complex queries
- Bulk Operations - Efficient batch updates and deletes
IEFUnitOfWork<TDbContext>
- Transaction management- Multi-Repository Transactions - Coordinate changes across entities
- Rollback Support - Automatic error handling
- 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
- 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
- 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
- JSON Support -
JSON_VALUE
for SQL Server 2016+ - SQL Server Functions - Enhanced querying capabilities
π Getting Started Guide - Step-by-step setup instructions for new users
π Complete Usage Guide - Comprehensive documentation with examples for all features
β‘ Advanced Features Guide - Custom interceptors, performance optimization, and integration patterns
π Release Notes - Version history and breaking changes
π§ Sample Project - Working examples and demonstrations
π‘ Questions? Check out the Usage Guide for detailed examples
π Found a bug or need help? Feel free to create an issue with reproduction steps
For detailed usage instructions, please refer to the Usage Documentation.