DataExplorer.EfCore
3.0.5
See the version list below for details.
dotnet add package DataExplorer.EfCore --version 3.0.5
NuGet\Install-Package DataExplorer.EfCore -Version 3.0.5
<PackageReference Include="DataExplorer.EfCore" Version="3.0.5" />
paket add DataExplorer.EfCore --version 3.0.5
#r "nuget: DataExplorer.EfCore, 3.0.5"
// Install DataExplorer.EfCore as a Cake Addin #addin nuget:?package=DataExplorer.EfCore&version=3.0.5 // Install DataExplorer.EfCore as a Cake Tool #tool nuget:?package=DataExplorer.EfCore&version=3.0.5
DataExplorer.EfCore
Library featuring a combination of Unit of Work, Repository, Specification and Data Service patterns.
Installation
Base DataExplorer package is required.
To register the library services with the DI container use the DataExplorerConfiguration extension method provided by the library:
builder.AddDataExplorer(options =>
{
options.AddEfCore(assembliesToScan);
});
Description
Library provides definition of a base entity (with generic Id and with long Id) which should be inherited by any entity defined within application's domain.
public class CustomEntity : Entity<long>
{
public bool CustomField { get; set; }
}
You can also implement IUpdatedAt
and/or ICreatedAt
interfaces to let the library handle the metadata properties automatically.
Library supports soft deletion via a IsDisabled
property on entities, you can mark an entity as a soft deleted entity using IDisableableEntity
interface.
Snowflake IDs are supported using an IdGenerator, to mark an entity to use snowflake IDs inherit from SnowflakeEntity
or implement ISnowflakeEntity
interface and override the Id property. Ids can be generated by a provided IdGenerator
which you can add as a singleton service via AddIdGen()
To avoid LINQ boilerplate a specification pattern is used to encapsulate query logic and should be used like so:
public CustomSpecification : Specification<CustomEntity>
{
public CustomSpecification(bool customField)
{
Where(x => x.CustomField == customField);
}
}
EF 7 ExecuteDeleteAsync
and ExecuteUpdateAsync
methods are now supported. In order to use the update method you must create a Specification
that inherits from UpdateSpecification<TEntitiy>
:
public CustomUpdateSpecification : UpdateSpecification<CustomEntity>
{
public CustomUpdateSpecification(bool customField)
{
Where(x => x.CustomField == customField);
Modify(x => x.SetProperty(p => p.CustomField, !customField));
}
}
Please use IntelliSense to check for available methods but pretty much everything should be supported by now.
Every data service automatically grabs it's corresponding entity repository from the Unit of Work and exposes it via properties, you can however do anything and everything through exposed DbContext, UnitOfWork, Mapper and other properties.
Getting a repository is done through methods on IUnitOfWork
:
unitOfWork.GetRepository<IRepository<CustomEntity>>();
Please use IntelliSense to find other helpful get repo methods. You can't (without reflection magic) create custom repository implementations, their constructor is internal, you can only get generic repos with the methods exposed via IUnitOfWork
, any custom, additional logic, should be performed in the service layer.:
Given below context definitions (always abstract your own context) - either manually register your context interface as a service or use AddDbContext
methods on DataExplorerEfCoreConfiguration
.
public interface ICustomDbContext : IEfDbContext
{
}
public class CustomDbContext : EfDbContext, ICustomDbContext
{
}
You can define a crud data service like so to add some custom logic:
public interface ICustomDataService : ICrudDataService<CustomEntity, ICustomDbContext>
{
Task<Result> GetFirstEntityWithCustomFieldTrueAndPerformLogicAsync();
}
public class CustomDataService : CrudDataService<CustomEntity, ICustomDbContext>, ICustomDataService
{
public async Task<Result> GetFirstEntityWithCustomFieldTrueAndPerformLogicAsync()
{
var entityRes = await GetSingleBySpecAsync(new CustomSpecification(true));
if (!entityRes.IsDefined(out var entity))
return entityRes;
/// perform custom logic on entity or whatnot
return Result.FromSuccess();
}
}
You can also simply inject a generic data service to perform simple operations like so:
public class CustomController : ControllerBase
{
private readonly IReadOnlyDataService<CustomEntity,ICustomDbContext> _dataService;
public CustomController(IReadOnlyDataService<CustomEntity,ICustomDbContext> dataService)
=> _dataService = dataService;
[HttpGet]
public async Task<IActionResult> GetAllByCustomFieldAsync(bool customField)
{
var subRes = await _dataService.GetBySpecAsync(new CustomSpecification(customField)); // or GetBySpecAsync<SomeDto> to automatically map the entity using AutoMapper
if (!subRes.IsDefined(out var result))
return BadRequest();
return Ok(result);
}
}
All service methods should return a Result struct which determines whether the operation succeeded or not and returns additional objects if necessary and shouldn't throw exceptions unless absolutely necessary.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
net6.0
- DataExplorer (>= 3.0.5)
- EFCoreSecondLevelCacheInterceptor (>= 4.2.0)
- Gridify.EntityFramework (>= 2.13.1)
- Microsoft.EntityFrameworkCore (>= 6.0.25 && <= 7.0.14)
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.25 && <= 7.0.14)
-
net7.0
- DataExplorer (>= 3.0.5)
- EFCoreSecondLevelCacheInterceptor (>= 4.2.0)
- Gridify.EntityFramework (>= 2.14.1)
- Microsoft.EntityFrameworkCore (>= 7.0.14)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.14)
-
net8.0
- DataExplorer (>= 3.0.5)
- EFCoreSecondLevelCacheInterceptor (>= 4.2.0)
- Gridify.EntityFramework (>= 2.14.1)
- Microsoft.EntityFrameworkCore (>= 8.0.2)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.2)
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.2.1 | 112 | 8/2/2024 |
3.2.0 | 98 | 8/2/2024 |
3.1.1 | 77 | 7/23/2024 |
3.1.0 | 135 | 7/11/2024 |
3.0.5 | 176 | 2/16/2024 |
3.0.4 | 133 | 1/25/2024 |
3.0.3 | 181 | 1/4/2024 |
3.0.2 | 219 | 11/22/2023 |
3.0.1 | 136 | 11/21/2023 |
3.0.0 | 120 | 11/20/2023 |
2.3.12 | 160 | 9/12/2023 |
2.3.11 | 168 | 9/1/2023 |
2.3.10 | 174 | 8/31/2023 |
2.3.9 | 160 | 8/31/2023 |
2.3.8 | 174 | 8/31/2023 |
2.3.7 | 180 | 8/30/2023 |
2.3.6 | 172 | 8/30/2023 |
2.3.5 | 187 | 8/30/2023 |
2.3.3 | 203 | 8/18/2023 |
2.3.2 | 214 | 8/8/2023 |
2.3.1 | 202 | 7/13/2023 |
2.3.0 | 198 | 7/11/2023 |
2.2.9 | 185 | 7/10/2023 |
2.2.8 | 228 | 6/25/2023 |
2.2.7 | 166 | 5/31/2023 |
2.2.6 | 198 | 5/17/2023 |
2.2.5 | 224 | 5/10/2023 |
2.2.4 | 249 | 4/14/2023 |
2.2.3 | 248 | 4/14/2023 |
2.2.2 | 233 | 4/14/2023 |
2.2.1 | 251 | 4/7/2023 |
2.2.0 | 280 | 3/14/2023 |
2.1.10 | 323 | 2/26/2023 |
2.1.9 | 296 | 2/26/2023 |
2.1.8 | 294 | 2/23/2023 |
2.1.7 | 291 | 2/23/2023 |
2.1.6 | 285 | 2/21/2023 |
2.1.5 | 288 | 2/21/2023 |
2.1.4 | 299 | 2/15/2023 |
2.1.3 | 314 | 2/3/2023 |
2.1.2 | 349 | 1/28/2023 |
2.1.1 | 359 | 1/22/2023 |
2.1.0 | 347 | 1/22/2023 |
2.0.8 | 362 | 1/11/2023 |
2.0.7 | 349 | 1/11/2023 |
2.0.6 | 354 | 1/9/2023 |
2.0.5 | 354 | 1/9/2023 |
2.0.4 | 427 | 11/21/2022 |
2.0.3 | 413 | 11/21/2022 |
2.0.2 | 393 | 11/19/2022 |
2.0.1 | 398 | 11/19/2022 |
2.0.0 | 379 | 11/19/2022 |
1.1.10 | 386 | 11/18/2022 |
1.1.9 | 448 | 9/27/2022 |
1.1.8 | 463 | 9/26/2022 |
1.1.7 | 493 | 9/24/2022 |
1.1.6 | 453 | 9/21/2022 |
1.1.5 | 437 | 9/19/2022 |
1.1.4 | 474 | 9/19/2022 |
1.1.3 | 452 | 9/19/2022 |
1.1.2 | 473 | 9/19/2022 |
1.1.0 | 483 | 9/17/2022 |
1.0.16 | 453 | 9/8/2022 |
1.0.15 | 476 | 8/29/2022 |
1.0.14 | 454 | 8/29/2022 |
1.0.13 | 509 | 8/29/2022 |
1.0.12 | 449 | 8/29/2022 |
1.0.11 | 454 | 8/29/2022 |
1.0.10 | 465 | 8/25/2022 |
1.0.8 | 448 | 8/25/2022 |
1.0.7 | 446 | 8/25/2022 |
1.0.6 | 451 | 8/25/2022 |
1.0.5 | 453 | 8/24/2022 |
1.0.4 | 448 | 8/23/2022 |
1.0.3 | 472 | 8/23/2022 |
1.0.2 | 460 | 8/23/2022 |
1.0.1 | 461 | 8/22/2022 |