Build, Test and Analyze .NET pages-build-deployment Qodana

Quality Gate Status Coverage

Package Version Downloads
Ploch.Data.Model version downloads
Ploch.Data.GenericRepository version downloads
Ploch.Data.GenericRepository.EFCore version downloads
Ploch.Data.EFCore version downloads

Ploch.Data Libraries

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.

Quick Start

// 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
services.AddDbContext<MyDbContext>(options => options.UseSqlite(connectionString));
services.AddRepositories<MyDbContext>(configuration);

// 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));
}

Documentation

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.Model interfaces
  • Generic Repository Guide -- repository operations, Unit of Work, DI registration, specifications
  • 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

Sample Application

A fully working Sample Application demonstrates entity modelling, repository operations, Unit of Work, pagination, eager loading, and integration testing.

Packages

Core

Package Description
Ploch.Data.Model Standardised entity interfaces (IHasId, INamed, IHasTitle, IHasAuditProperties, etc.) and common base types (Category, Tag, Property)

Entity Framework Core

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

Generic Repository

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.DependencyInjection ServicesBundle integration for Ploch.Common
Ploch.Data.GenericRepository.EFCore.Specification Ardalis.Specification integration

Testing

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

Utilities

Package Description
Ploch.Data.Utilities Various utility types for working with data
Ploch.Data.StandardDataSets Common datasets (country lists, regions, etc.)

Features

Common Data Model

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

Generic Repository and Unit of Work

A generic repository and unit of work pattern implementation for Entity Framework Core:

  • Layered repository interfaces: IQueryableRepository, IReadRepositoryAsync, IReadWriteRepositoryAsync
  • Unit of Work: IUnitOfWork with CommitAsync() and RollbackAsync()
  • One-line DI registration: services.AddRepositories<MyDbContext>()
  • Custom repository support with full interface registration
  • Specification pattern integration via Ardalis.Specification
  • Automatic audit property handling

Entity Framework Core Utilities

Utility classes for EF Core including design-time DbContext factory base classes, runtime configurators for SQLite and SQL Server, and the SQLite DateTimeOffset workaround.

Integration Testing

Base classes for integration tests using in-memory SQLite databases with automatic schema creation, repository helpers, and Unit of Work support.

Common Datasets

Common data sets like country lists and regions.

Data Utilities

Various utilities for working with data.

  • Improve this Doc
In This Article
Back to top Generated by DocFX