Mecesoft.Repository 1.0.1

dotnet add package Mecesoft.Repository --version 1.0.1
                    
NuGet\Install-Package Mecesoft.Repository -Version 1.0.1
                    
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="Mecesoft.Repository" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mecesoft.Repository" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Mecesoft.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 Mecesoft.Repository --version 1.0.1
                    
#r "nuget: Mecesoft.Repository, 1.0.1"
                    
#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 Mecesoft.Repository@1.0.1
                    
#: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=Mecesoft.Repository&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Mecesoft.Repository&version=1.0.1
                    
Install as a Cake Tool

Mecesoft.Repository

Lightweight, generic repository implementation for Entity Framework Core. Provides a minimal API surface for common data access operations with optional soft-delete awareness (IgnoreQueryFilters) and tracking control (AsNoTracking/AsTracking).

  • Target Framework: .NET 9 (net9.0)
  • Dependency: Microsoft.EntityFrameworkCore

Installation

NuGet (once published):

Install-Package Mecesoft.Repository

or with dotnet CLI:

dotnet add package Mecesoft.Repository

Quick Start

using Microsoft.EntityFrameworkCore;
using Mecesoft.Repository;

// Your DbContext
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
    public DbSet<User> Users => Set<User>();
}

public class User
{
    public string Id { get; set; } = Guid.NewGuid().ToString();
    public string Name { get; set; } = string.Empty;
    // Optional soft delete column if you use global query filters in your context
    public bool IsDeleted { get; set; }
}

// Register in DI (Program.cs)
// services.AddDbContext<AppDbContext>(...);
// services.AddScoped<IRepository<User>, Repository<User, AppDbContext>>();

// Use in a service
public class UserService(IRepository<User> users, AppDbContext db) 
{
    public async Task<string?> CreateAsync(string name, CancellationToken ct)
    {
        var entity = new User { Name = name };
        await users.AddAsync(entity, ct);
        await db.SaveChangesAsync(ct); // repository does not call SaveChanges
        return entity.Id;
    }

    public Task<User?> GetAsync(string id, CancellationToken ct)
        => users.GetByExpressionAsync(u => u.Id == id, ct);
}

Repository API Overview

The repository interface is IRepository<TEntity>.

  • Query

    • IQueryable<TEntity> GetAll(bool includeDeleted = false, bool asNoTracking = true)
    • IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> predicate, bool includeDeleted = false, bool asNoTracking = true)
    • TEntity? GetByExpression(...) and Task<TEntity?> GetByExpressionAsync(...)
    • Task<TResult?> GetByExpressionDtoAsync<TResult>(predicate, selector, ...) (projection)
    • TEntity? GetFirst(...) and Task<TEntity?> GetFirstAsync(...)
    • bool Any(...) and Task<bool> AnyAsync(...)
  • Mutations

    • void Add(TEntity entity) and Task AddAsync(TEntity entity, CancellationToken)
    • Task AddRangeAsync(ICollection<TEntity> entities, CancellationToken)
    • void Update(TEntity entity) and void UpdateRange(ICollection<TEntity> entities)
    • void Delete(TEntity entity) and void DeleteRange(ICollection<TEntity> entities)
    • Task DeleteByIdAsync(string id)
    • Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken)
  • Tracking helpers

    • GetByExpressionWithTrackingAsync(...) and GetAllExpressionWithTrackingAsync(...) to force tracking even when global no-tracking is used.

Notes:

  • The repository does not call SaveChanges/SaveChangesAsync. Commit using your DbContext or a Unit of Work.
  • Soft delete: pass includeDeleted: true to bypass EF Core global query filters.
  • Tracking: for read operations, default is AsNoTracking to improve performance. Set asNoTracking: false when you plan to update returned entities.

Soft Delete and Global Filters

If you use global filters (e.g. modelBuilder.Entity<User>().HasQueryFilter(x => !x.IsDeleted)), you can opt-in to include filtered rows with includeDeleted: true in query methods.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
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
1.0.1 376 9/16/2025
1.0.0 275 9/16/2025