| Package | Version | Downloads |
|---|---|---|
| Ploch.Data.Model | ||
| Ploch.Data.GenericRepository | ||
| Ploch.Data.GenericRepository.EFCore | ||
| Ploch.Data.EFCore |
A set of .NET libraries for building data access layers using standardised entity models, the Generic Repository and Unit of Work patterns, and Entity Framework Core.
If Ploch.Data saves you time or makes your projects nicer, please consider supporting its development. Every coffee directly funds time spent on maintenance, bug fixes, and new features.
Thank you for keeping open-source maintainers caffeinated.
// 1. Define entities using Ploch.Data.Model interfaces
public class Product : IHasId<int>, IHasTitle, IHasDescription, IHasAuditTimeProperties
{
public int Id { get; set; }
public string Title { get; set; } = null!;
public string? Description { get; set; }
public DateTimeOffset? CreatedTime { get; set; }
public DateTimeOffset? ModifiedTime { get; set; }
public DateTimeOffset? AccessedTime { get; set; }
}
// 2. Register in DI (reference Ploch.Data.GenericRepository.EFCore.SqLite
// or Ploch.Data.GenericRepository.EFCore.SqlServer — same code for both)
using Ploch.Data.GenericRepository.EFCore.DependencyInjection;
builder.Services.AddDbContextWithRepositories<MyDbContext>();
// 3. Inject and use repositories
public class ProductService(IReadWriteRepositoryAsync<Product, int> repository)
{
public Task<Product?> GetAsync(int id) => repository.GetByIdAsync(id);
public Task<IList<Product>> SearchAsync(string term)
=> repository.GetAllAsync(p => p.Title.Contains(term));
}Full documentation is available in the docs/ folder:
- Getting Started -- quick start guides for common use cases
- Data Model Guide -- complete reference for
Ploch.Data.Modelinterfaces - Generic Repository Guide -- repository operations, Unit of Work, specifications
- Dependency Injection Guide -- DI registration, provider switching (SQLite/SQL Server), lifecycle plugins, connection string configuration
- Data Project Setup -- step-by-step guide for creating Data and provider projects
- Integration Testing -- testing with in-memory SQLite, base test classes
- Extending the Libraries -- custom repositories, new providers, extensibility
- Architecture Overview -- package dependencies and design
A fully working Sample Application demonstrates entity modelling, repository operations, Unit of Work, pagination, eager loading, and integration testing.
| Package | Description |
|---|---|
| Ploch.Data.Model | Standardised entity interfaces (IHasId, INamed, IHasTitle, IHasAuditProperties, etc.) and common base types (Category, Tag, Property) |
| Package | Description |
|---|---|
| Ploch.Data.EFCore | Design-time factory base classes, IDbContextConfigurator, data seeding, value converters |
| Ploch.Data.EFCore.SqLite | SQLite provider: factory, configurator, DateTimeOffset workaround |
| Ploch.Data.EFCore.SqlServer | SQL Server provider: factory, configurator |
| Package | Description |
|---|---|
| Ploch.Data.GenericRepository | Provider-agnostic repository and Unit of Work interfaces |
| Ploch.Data.GenericRepository.EFCore | EF Core implementations, DI registration via AddRepositories<TDbContext>() |
| Ploch.Data.GenericRepository.EFCore.SqLite | One-call DI registration for SQLite (AddDbContextWithRepositories<TDbContext>()) |
| Ploch.Data.GenericRepository.EFCore.SqlServer | One-call DI registration for SQL Server (AddDbContextWithRepositories<TDbContext>()) |
| Ploch.Data.GenericRepository.EFCore.Specification | Ardalis.Specification integration |
| Package | Description |
|---|---|
| Ploch.Data.EFCore.IntegrationTesting | DataIntegrationTest<TDbContext> base class for EF Core tests |
| Ploch.Data.GenericRepository.EFCore.IntegrationTesting | GenericRepositoryDataIntegrationTest<TDbContext> with repository/UoW helpers |
| Package | Description |
|---|---|
| Ploch.Data.Utilities | Various utility types for working with data |
| Ploch.Data.StandardDataSets | Common datasets (country lists, regions, etc.) |
A set of interfaces and base types for standardising entity models:
- Core interfaces:
IHasId<TId>,INamed,IHasTitle,IHasDescription,IHasContents,IHasNotes,IHasValue<TValue> - Audit interfaces:
IHasAuditProperties,IHasAuditTimeProperties(and individual timestamp/user interfaces) - Hierarchical interfaces:
IHierarchicalParentChildrenComposite<T>for tree structures - Categorisation:
IHasCategories<TCategory>,IHasTags<TTag> - Common types:
Category<T>,Tag,Property<TValue>,StringProperty,IntProperty,Image
A generic repository and unit of work pattern implementation for Entity Framework Core:
- Layered repository interfaces:
IQueryableRepository,IReadRepositoryAsync,IReadWriteRepositoryAsync - Unit of Work:
IUnitOfWorkwithCommitAsync()andRollbackAsync() - One-line DI registration:
services.AddDbContextWithRepositories<MyDbContext>()(provider-specific) orservices.AddRepositories<MyDbContext>()(manual) - Zero-code database provider switching between SQLite and SQL Server
- Pluggable
IDbContextCreationLifecyclefor provider-specific model configuration - Custom repository support with full interface registration
- Specification pattern integration via Ardalis.Specification
- Automatic audit property handling
Utility classes for EF Core including design-time DbContext factory base classes, runtime configurators for SQLite and SQL Server, and the SQLite DateTimeOffset workaround.
Base classes for integration tests using in-memory SQLite databases with automatic schema creation, repository helpers, and Unit of Work support.
Common data sets like country lists and regions.
Various utilities for working with data.