SimpleEfCoreRepository 3.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SimpleEfCoreRepository --version 3.0.1
NuGet\Install-Package SimpleEfCoreRepository -Version 3.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="SimpleEfCoreRepository" Version="3.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleEfCoreRepository" Version="3.0.1" />
<PackageReference Include="SimpleEfCoreRepository" />
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 SimpleEfCoreRepository --version 3.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimpleEfCoreRepository, 3.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 SimpleEfCoreRepository@3.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=SimpleEfCoreRepository&version=3.0.1
#tool nuget:?package=SimpleEfCoreRepository&version=3.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EF.Core.Repository
Simple repository for Ef.Core with basic CRUD functionality The reason I implemented this is because I found myself re-writing basic CRUD functionality over and over again. Most of the time:
- use
.include(...)to include eager load associated entities - update (add/delete/update) children properties
Using repository pattern with entity framework enforces a consistent convention and that is what this library is aiming towards.
Basic setup
- Entity should have Id property. Using
[Key]is optional if Id property does not follow common naming convention.
public class DummyModel
{
public string Name { get; set; }
public List<Nested> Children { get; set; }
}
- Create profile which is used to update an entity given a DTO
public class DummyModelProfile : EntityProfile<DummyModel>
{
public override void Update(DummyModel entity, DummyModel dto)
{
entity.Name = dto.Name;
// ModifyList will try to add/delete entities based on Id based on whether they
// appear in dto.Children or not
ModifyList(entity.Children, dto.Children, x => x.Id);
}
// Intercept IQueryable to include related entities
public override IQueryable<DummyModel> Include<TQueryable>(TQueryable queryable) where TQueryable : IQueryable<DummyModel>
{
return queryable.Include(x => x.Children);
}
}
- Register dependency via
IServiceCollectionextension
var serviceProvider = services
.AddEfRepository<EntityDbContext>(options => options
.Profile(Assembly.GetExecutingAssembly()));
- Use
IBasicCrud
IEfRepository repo = ... // DI inject IEfRepository
// Get IBasicCrud instance
IBasicCrud<DummyModel> = repo.For<DummyModel>();
- Available methods in
IBasicCrud
// Get all entities without any filter
Task<IEnumerable<TSource>> GetAll();
// Get all entities given an array of Ids
Task<IEnumerable<TSource>> GetAll<TId>(param TId[]);
// Get all entities given a filter expression
Task<IEnumerable<TSource>> GetAll(Expression<Func<TSource, bool>>);
// Get single entity by Id
Task<TSource> Get<TId>(TId);
// Get single entity given a filter expression
Task<TSource> Get(Expression<Func<TSource, bool>>);
// Save entity
Task<TSource> Save(TSource);
// Save multiple entities
Task<IEnumerable<TSource>> Save(param TSource[]);
// Update entity by Id
Task<TSource> Update<TId>(TId, TSource);
// Update entity manually
Task<TSource> Update<TId>(TId, Action<TSource>);
// Update entity by filter expression
Task<TSource> Update(Expression<Func<TSource, bool>>, TSource);
// Update entity manually by filter expression
Task<TSource> Update(Expression<Func<TSource, bool>>, Action<TSource>);
// Delete entity by Id
Task<TSource> Delete<TId>(TId);
// Delete entity given a filter expression
Task<TSource> Delete(Expression<Func<TSource, bool>>);
// This is useful if you want to defer SaveChanges in session mode
// Changes are not automatically saved back to DbContext in session mode
IBasicCrud<TSource, TId> Delayed();
// This is useful if you want don't want to include all related entities
// or turn entities into a "god" object
IBasicCrud<TSource, TId> Light();
Notes:
- "Id" has a type constraint of
: struct, which means it accepts all primitive types includingGUIDandString. - Including all associated entities will lead to "god object" which is anti-pattern. I recommend using this library as L2 cache
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Microsoft.EntityFrameworkCore (>= 3.1.0)
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.1.20 | 99 | 2/14/2026 |
| 3.1.19 | 84 | 2/13/2026 |
| 3.1.18 | 122 | 1/10/2026 |
| 3.1.17 | 90 | 1/10/2026 |
| 3.1.16 | 371 | 8/9/2025 |
| 3.1.15 | 312 | 6/16/2025 |
| 3.1.14 | 1,049 | 4/4/2025 |
| 3.1.13 | 199 | 4/4/2025 |
| 3.1.12 | 197 | 4/4/2025 |
| 3.1.11 | 220 | 4/3/2025 |
| 3.1.10 | 258 | 3/31/2025 |
| 3.1.8 | 637 | 3/24/2025 |
| 3.1.7 | 513 | 3/24/2025 |
| 3.1.6 | 389 | 3/24/2025 |
| 3.1.5 | 219 | 3/23/2025 |
| 3.1.4 | 132 | 3/22/2025 |
| 3.1.3 | 230 | 3/19/2025 |
| 3.1.2 | 398 | 3/4/2025 |
| 3.1.1 | 229 | 2/25/2025 |
| 3.0.1 | 855 | 7/12/2022 |
Loading failed
Added new update method.