Vertizens.SliceR.Operations.EntityFrameworkCore 1.0.0

dotnet add package Vertizens.SliceR.Operations.EntityFrameworkCore --version 1.0.0                
NuGet\Install-Package Vertizens.SliceR.Operations.EntityFrameworkCore -Version 1.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="Vertizens.SliceR.Operations.EntityFrameworkCore" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Vertizens.SliceR.Operations.EntityFrameworkCore --version 1.0.0                
#r "nuget: Vertizens.SliceR.Operations.EntityFrameworkCore, 1.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.
// Install Vertizens.SliceR.Operations.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Vertizens.SliceR.Operations.EntityFrameworkCore&version=1.0.0

// Install Vertizens.SliceR.Operations.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Vertizens.SliceR.Operations.EntityFrameworkCore&version=1.0.0                

SliceR.Operations.EntityFrameworkCore

Adds EntityFramework Core boilerplate functionality for working with entities to SliceR.

Getting Started

If you use EntityFramework Core for doing data access then this library can look at the registered DbContext types and for each entity register a IHandler that are these types: NoFilterQueryableHandler, ByKeyHandler (if primary key), DeleteHandler (if primary key), InsertHandler, and UpdateHandler.

Do this by registering these default handlers after the DbContext types have been registered. Take care that to be able to get the list of entities the code creates the DbContext in this method so make sure they can be created according to their dependencies up to this point. Also confirm that each entity only exists in one DbContext if there are multiple.

services.AddSliceREntityFrameworkCoreDefaultHandlers();

Default Handlers

NoFilterQueryableHandler<TEntity> - Use NoFilter type to signify that no parameters are passed in.
Use it by injecting: IHandler<NoFilter,IQueryable<TEntity>> into your handler.

ByKeyHandler<TKey, TEntity> - Use ByKey<TKey> type to specify the key for the entity.
Use it by injecting: IHandler<ByKey<TKey>,TEntity?> into your handler.

InsertHandler<TEntity> - Use Insert<TEntity> type to specify the entity to insert.
Use it by injecting: IHandler<Insert<TEntity>,TEntity> into your handler. Calls dbContext.SaveChangesAsync();

UpdateHandler<TEntity> - Use Update<TEntity> type to specify the entity to update.
Use it by injecting: IHandler<Update<TEntity>,TEntity> into your handler. Calls dbContext.SaveChangesAsync();

DeleteHandler<TKey, TEntity> - Use Delete<TKey, TEntity> type to specify the entity type and key to delete.
Use it by injecting: IHandler<Delete<TKey, TEntity>, bool> into your handler. It returns true if records affected are > 0.

Custom DbContext Operations

If you have custom queries or multiple operations that need to take place in the same handler simply create a custom handler. Inject the DbContext like normal or possibly use IEntityDbContextResolver if you have multiple DbContext and don't want to hardcode which DbContext it is defined in.
Make sure to register custom handlers first with:

services.AddSlicerRHandlers();

Keys

When registering handlers, the code looks for a registered service type of IKeyPredicate<,> where the second generic type is the entity. If found then the first generic type must be the key type to be used. By implementing IKeyPredicate then it takes over the definition of what key an entity uses and provides a way to get an entity and match the key with its expression definiton. The GetPredicate method returns Expression<Func<TEntity, TKey, bool>>. If not specifically implemented and the entity primary key is only one property then the key is assumed to be the type of that one property. If the key is has multiple properties, ie compound key, then no key based handlers are registered unless the IKeyPredicate is registered.

Domain and Minimal APIs

If the code is also using Minimal API or just rolling its own handlers for using this library with domain projection then an implementation of IEntityDomainHandlerRegistrar is registered. This allows this library to respond to Entity/Domain combinations by also registering any handlers required for returning domain instead of an entity. Examples are:

  • NoFilterQueryableHandler<TEntity, TDomain>
  • ByKeyHandler<TKey, TEntity, TDomain>
  • ByKeyForUpdateHandler<TKey, TUpdateDomain, TEntity>

There reason ByKeyForUpdateHandler exists is the special case where we want to get the existing entity and map onto to it from TUpdateDomain and that could also mean any relationships and treat the entity as a graph update. There is special code that looks at the mapping of TUpdateDomain to TEntity and adds any Includes to the queryable getting the existing TEntity so it can be mapped to and allow EF Core to update relationships instances.

Product Compatible and additional computed target framework versions.
.NET 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.  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. 
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.0 96 12/7/2024
0.5.0-rc.1.5 57 12/5/2024
0.5.0-rc.1.4 53 12/4/2024
0.5.0-rc.1.2 57 11/28/2024
0.5.0-rc.1.1 55 11/25/2024
0.5.0-rc.1 63 11/22/2024
0.4.0-rc.1.3 52 11/17/2024
0.4.0-rc.1.2 57 11/16/2024
0.4.0-rc.1.1 54 11/15/2024
0.4.0-rc.1 54 11/15/2024
0.3.0-rc.1.1 71 11/11/2024
0.3.0-rc.1 66 11/11/2024
0.2.0-rc.1 62 11/3/2024
0.0.0-alpha.0.1 61 11/3/2024