Mecesoft.Repository
1.0.1
dotnet add package Mecesoft.Repository --version 1.0.1
NuGet\Install-Package Mecesoft.Repository -Version 1.0.1
<PackageReference Include="Mecesoft.Repository" Version="1.0.1" />
<PackageVersion Include="Mecesoft.Repository" Version="1.0.1" />
<PackageReference Include="Mecesoft.Repository" />
paket add Mecesoft.Repository --version 1.0.1
#r "nuget: Mecesoft.Repository, 1.0.1"
#:package Mecesoft.Repository@1.0.1
#addin nuget:?package=Mecesoft.Repository&version=1.0.1
#tool nuget:?package=Mecesoft.Repository&version=1.0.1
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(...)
andTask<TEntity?> GetByExpressionAsync(...)
Task<TResult?> GetByExpressionDtoAsync<TResult>(predicate, selector, ...)
(projection)TEntity? GetFirst(...)
andTask<TEntity?> GetFirstAsync(...)
bool Any(...)
andTask<bool> AnyAsync(...)
Mutations
void Add(TEntity entity)
andTask AddAsync(TEntity entity, CancellationToken)
Task AddRangeAsync(ICollection<TEntity> entities, CancellationToken)
void Update(TEntity entity)
andvoid UpdateRange(ICollection<TEntity> entities)
void Delete(TEntity entity)
andvoid DeleteRange(ICollection<TEntity> entities)
Task DeleteByIdAsync(string id)
Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken)
Tracking helpers
GetByExpressionWithTrackingAsync(...)
andGetAllExpressionWithTrackingAsync(...)
to force tracking even when global no-tracking is used.
Notes:
- The repository does not call
SaveChanges
/SaveChangesAsync
. Commit using yourDbContext
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. SetasNoTracking: 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 | Versions 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.