EFCoreLayerKit 1.0.5
dotnet add package EFCoreLayerKit --version 1.0.5
NuGet\Install-Package EFCoreLayerKit -Version 1.0.5
<PackageReference Include="EFCoreLayerKit" Version="1.0.5" />
<PackageVersion Include="EFCoreLayerKit" Version="1.0.5" />
<PackageReference Include="EFCoreLayerKit" />
paket add EFCoreLayerKit --version 1.0.5
#r "nuget: EFCoreLayerKit, 1.0.5"
#:package EFCoreLayerKit@1.0.5
#addin nuget:?package=EFCoreLayerKit&version=1.0.5
#tool nuget:?package=EFCoreLayerKit&version=1.0.5
EFCoreLayerKit
EFCoreLayerKit is a general-purpose data access layer toolkit based on Entity Framework Core. It supports automatic repository registration, DTO mapping, soft deletion, automatic migration, and more. Suitable for .NET 8+ projects.
Features
- Automatically register all DbContexts inheriting from
BaseDbContext
and migrate database schema - Automatically register all repositories inheriting from
BaseRepository<TEntity>
- Support for soft delete, optimistic concurrency, batch operations, and other common data access patterns
- Automatic two-way mapping between DTOs and entities (based on AutoMapper)
- Rich result types (
FResult
,FResult<T>
,FPagedResult<T>
) - Designed for DI scenarios such as Blazor and ASP.NET Core
Installation
Make sure your project references the following NuGet packages:
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.Sqlite
- AutoMapper
- System.Linq.Dynamic.Core
- EFCoreLayerKit (this library)
Quick Start
- Define Entities and DbContext public class Author : BaseEntity { public string Name { get; set; } public virtual ICollection<Book> Books { get; set; } }
public class Book : BaseEntity { public string Title { get; set; } public long AuthorId { get; set; } public virtual Author Author { get; set; } }
public class TestDbContext : BaseDbContext { public DbSet<Author> Authors { get; set; } public DbSet<Book> Books { get; set; } } 2. Define Repository Classes public class AuthorRepository : BaseRepository<Author> { public AuthorRepository(TestDbContext ctx) : base(ctx) { } }
public class BookRepository : BaseRepository<Book> { public BookRepository(TestDbContext ctx) : base(ctx) { } } 3. Register Services and Auto-Migrate
In Program.cs
:
var services = new ServiceCollection();
services.AddEFCoreLayerKit();
var provider = services.BuildServiceProvider();
All DbContexts will automatically call EnsureDatabaseMigrated()
during registration, so you do not need to manually migrate.
- Use Repositories for Data Operations var authorRepo = provider.GetRequiredService<AuthorRepository>(); var bookRepo = provider.GetRequiredService<BookRepository>();
// Add data var author = new Author { Name = "Zhang San" }; var addAuthorResult = await authorRepo.AddAsync(author);
var book = new Book { Title = "C# Beginner", AuthorId = author.Id }; var addBookResult = await bookRepo.AddAsync(book);
// Query authors = await authorRepo.GetAllAsync();
// Update author.Name = "Li Si"; var updateAuthorResult = await authorRepo.UpdateAsync(author);
// Delete var deleteAuthorResult = await authorRepo.DeleteAsync(author.Id);
Result Types
FResult
: General operation result, including success flag, message, error code, etc.FResult<T>
: Operation result with data.FPagedResult<T>
: Paged result with data and pagination info.
All result types support formatted messages, error codes, and log conversion.
Advanced Usage
- Custom repositories, DTO mapping, global query filters
- Batch operations, soft delete, optimistic concurrency
- See source code comments and extension methods for more
Testing & Examples
A complete test project (EFCoreLayerKitTest
) is included. You can run Program.cs
to see CRUD and other features in action.
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- AutoMapper (>= 14.0.0)
- FormatLog (>= 1.0.7)
- Microsoft.EntityFrameworkCore.Sqlite (>= 9.0.7)
- System.Linq.Dynamic.Core (>= 1.6.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.