Opticient.EFCore.Repository 3.0.0

dotnet add package Opticient.EFCore.Repository --version 3.0.0
                    
NuGet\Install-Package Opticient.EFCore.Repository -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Opticient.EFCore.Repository" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Opticient.EFCore.Repository" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Opticient.EFCore.Repository" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Opticient.EFCore.Repository --version 3.0.0
                    
#r "nuget: Opticient.EFCore.Repository, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Opticient.EFCore.Repository@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Opticient.EFCore.Repository&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Opticient.EFCore.Repository&version=3.0.0
                    
Install as a Cake Tool

EFCore Repository

A lightweight and extensible Repository Pattern implementation for Entity Framework Core, designed to promote clean architecture, testability, and maintainability in .NET applications.

This library provides a structured abstraction over EF Core, allowing you to separate data access concerns from business logic while still leveraging EF Core’s full power.


Features

  • Clean implementation of the Repository Pattern.
  • Designed for Entity Framework Core.
  • Supports generic base entities and key-based entities.
  • Encourages testable and modular architecture.
  • Compatible with the Unit of Work pattern.
  • Minimal, opinionated abstractions without over-engineering.

Framework Support


Installation

Install via NuGet:

dotnet add package Opticient.EFCore.Repository

Or via the NuGet Package Manager:

Install-Package Opticient.EFCore.Repository

Alternatively, you may clone or download the source code and build it locally.


Usage

Entity Types

The library provides two base entity types:

  1. EntityBase

    • Base class for all entities.
    • All database tables without PrimaryKey (entities) should inherit from EntityBase.
  2. IdEntity<TKey>

    • Inherits from 'EntityBase' and for entities that expose a strongly typed primary key.
    • TKey - DataType of the Key (PrimaryKey in Db Table) of the Entity.
    • All database tables having PrimaryKey (entities) should inherit from IdEntity<TKey>.

Extending Entities

All Entities are abstract and are intended to be extended per entity (table):

public class Customer : IdEntity<int>
{
   // Add members of Customer Entity except 'Id'.
}

Repository Types

The library includes abstract base repositories that build upon each other to support common data access patterns:

  1. BaseRepository

    • A foundational base repository with no operations, intended to provide shared infrastructure for all repositories.
  2. EntityBaseRepository

    • Inherits from BaseRepository and provides basic read operations for entities derived from EntityBase.
  3. IdEntityReadRepository<TKey>

    • Inherits from EntityBaseRepository and extends read operations to support entities identified by a strongly typed primary key - IdEntity<TKey>.
  4. IdEntityRepository<TKey>

    • Inherits from IdEntityReadRepository<TKey> and adds support for create, update, and delete operations for entities identified by a strongly typed primary key - IdEntity<TKey>.

Extending Repositories

All Repositories are abstract and are intended to be extended per entity (table):

Example
public interface ICustomerRepository : IIdEntityRepository<Customer, int>
{
    // Add custom methods specific to Customer Entity.
}

public class CustomerRepository : IdEntityRepository<Customer, int>, ICustomerRepository
{
    public CustomerRepository(DbContext context, ILogger<CustomerRepository> logger) : base(context, logger)
    {
    }
}

Unit of Work

This library is designed to work seamlessly with the Unit of Work pattern.
You are free to implement your own IUnitOfWork abstraction on top of these repositories.

Example
public interface IUnitOfWork
{
    ICustomerRepository Customers{ get; }
}

public class UnitOfWork : IUnitOfWork
{
    private readonly DbContext _dbContext;
    private readonly ILoggerFactory _loggerFactory;
    private ICustomerRepository _customerRepository;

    public UnitOfWork(IDbContextFactory<DbContext> contextFactory, ILoggerFactory loggerFactory)
    {
        ArgumentNullException.ThrowIfNull(contextFactory);

        _dbContext = contextFactory.CreateDbContext();
        _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
    }
    public ICustomerRepository Customers => _customerRepository ??= new CustomerRepository(_dbContext, _loggerFactory.CreateLogger<CustomerRepository>());
}

Examples

For concrete examples of:

  • Entity definitions
  • Repository implementations
  • Usage patterns

Please refer to the Test project included in the solution.


Contributing

Contributions are welcome.

  • Found a bug? Create an issue.
  • Have a feature request? Start a discussion.
  • Want to contribute? Fork the repository and submit a pull request.

Please ensure all changes include appropriate tests.


License

Copyright © 2026 Opticient Ltd.

This project is licensed under the MIT License.
See https://opensource.org/licenses/MIT for details.


Contact

For questions, feedback, or support, please contact the author at Contact.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 168 1/5/2026
2.0.0 353 4/29/2023
1.0.1 597 6/6/2022
1.0.0 532 7/23/2021

Separate Repository for Read