Semantica.Lib.Storage.EntityFramework 8.1.0-beta

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

Semantica.Lib.Storage.EntityFramework

This package is part of the design packages of Semantica.Lib.

Summary

Provides implementations for the abstractions provided by Semantica.Lib.Storage that are dependent on EntityFramework. Has implementations for IDataStore (as base classes) for entities with or without simple keys, IInclusion, and IUnitOfWork. To use the datastore base classes, implementations of IPredicateProvider and IKeyConverter will have to be provided for the entity. For the other dependencies the provided standard implementations can be used.

The provided Module can be used to register all generic implementations. The RegisterDbContextFactory() extension method can be used to register the application's DbContext.

Also contains extensions for EntityTypeBuilder and PropertyBuilder to help with EntityFramework configuration.

Dependencies

  • Microsoft.EntityFrameworkCore
  • Semantica.Lib.Checks
  • Semantica.Lib.Core
  • Semantica.Lib.Domain
  • Semantica.Lib.Extensions
  • Semantica.Lib.Linq
  • Semantica.Lib.Ordering
  • Semantica.Lib.Patterns
  • Semantica.Lib.Storage
  • Semantica.Lib.Storage.Data
  • StoredProcedureEFCore

Documentation generated from the XMLDoc:

<a name='assembly'></a>

Lib.Storage.EntityFramework

Contents

<a name='T-Semantica-Storage-EntityFramework-DataStores-AggregateDataStore`2'></a>

AggregateDataStore`2 type

Namespace

Semantica.Storage.EntityFramework.DataStores

Summary

Implements datastore retrieval operations focussed on querying storables using a foreign key or otherwise aggregating key present on the table, with added functionality compared to CompositeAggregateDataStore`2 only possible when TAggregateKey is a simple key ().

The recommended way of leveraging this functionality for a storable for which you also have a ICompositeDataStore`2 implementation, is by making your datastore interface also inherit from IAggregateDataStore`2. The implementation of these methods can then be easily deferred to this standard implementation, which can be injected by using the IAggregateDataStoreInternal`2 interface. This standard generic implementation can be registered using Module. This implementation is only dependent on an implementation of IAggregatePredicateProvider`2 for the storable/key. This implementation can be the same class as your ICompositePredicateProvider`2 implementation of the same storable, but should be registered separately for the generic interface.

For more information check the README.howto.md of this project.

Generic Types
Name Description
TStorable The type of (entity framework) storable to retrieve
TAggregateKey The (foreign) simple key that aggregates TStorable

<a name='T-Semantica-Storage-EntityFramework-DataStores-CompositeAggregateDataStore`2'></a>

CompositeAggregateDataStore`2 type

Namespace

Semantica.Storage.EntityFramework.DataStores

Summary

Implements datastore retrieval operations focussed on querying storables using a foreign key or otherwise aggregating key present on the table.

The recommended way of leveraging this functionality for a storable for which you also have a ICompositeDataStore`2 implementation, is by making your datastore interface also inherit from ICompositeAggregateDataStore`2. The implementation of these methods can then be easily deferred to this standard implementation, which can be injected by using the ICompositeAggregateDataStoreInternal`2 interface. This standard generic implementation can be registered using Module. This implementation is only dependent on an implementation of IAggregatePredicateProvider`2 for the storable/key. This implementation can be the same class as your ICompositePredicateProvider`2 implementation of the same storable, but should be registered separately for the generic interface.

For more information check the README.howto.md of this project.

Generic Types
Name Description
TStorable The type of (entity framework) storable to retrieve
TAggregateKey The (foreign) key that aggregates TStorable

<a name='T-Semantica-Storage-EntityFramework-DataStores-CompositeDataStore`2'></a>

CompositeDataStore`2 type

Namespace

Semantica.Storage.EntityFramework.DataStores

Summary

Datastore is a standard implementation of ICompositeDataStore`2 that provides basic CRUD operations for one DbSet.

It is dependent on having an implementation injected of the ICompositePredicateProvider`2 of the same storable and key types to do entity framework dbset interactions. So this implementation will have to be mage and registered for each storable type. It is also dependent on having an implementation injected of the IKeyConverter`2 of the same storable and key types.

The class uses IStorageCache`2 to provide basic caching by key. The standard implementation registers itself to the IUnitOfWorkManager, and gets cleared every time a unit of work is completed.

If the key type maps to a single column in the database (a simple key), some of operations can be queried using a list. Use DataStore`2 instead. If dbset or dbcontext interaction is required for a storable but CRUD operations are not, inherit from the DataStoreBase`1 abstract class instead.

Generic Types
Name Description
TStorable Type of the storable (entity framework) class
TKey Type of the key

<a name='T-Semantica-Storage-EntityFramework-DataStores-DataStoreBase`1'></a>

DataStoreBase`1 type

Namespace

Semantica.Storage.EntityFramework.DataStores

Summary

Base class

Generic Types
Name Description
TStorable Storable (entity) type.

<a name='T-Semantica-Storage-EntityFramework-DataStores-DataStore`2'></a>

DataStore`2 type

Namespace

Semantica.Storage.EntityFramework.DataStores

Summary

Datastore is a standard implementation of IDataStore`2 that provides basic CRUD operations for one DbSet.

It is dependent on having an implementation injected of the IPredicateProvider`2 of the same storable and key types to do entity framework dbset interactions. So this implementation will have to be mage and registered for each storable type. It is also dependent on having an implementation injected of the IKeyConverter`2 of the same storable and key types.

The class uses IStorageCache`2 to provide basic caching by key. The standard implementation registers itself to the IUnitOfWorkManager, and gets cleared every time a unit of work is completed.

If the key type does maps to more than one column in the database (a composite key), it will not be possible to implement all requried methods of IPredicateProvider`2. In this casse, use CompositeDataStore`2 instead. If dbset or dbcontext interaction is required for a storable but CRUD operations are not, inherit from the DataStoreBase`1 abstract class instead.

Generic Types
Name Description
TStorable Type of the storable (entity framework) class
TKey Type of the key

<a name='T-Semantica-Storage-EntityFramework-DbContexts-DbContextFactory'></a>

DbContextFactory type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Inherit from parent.

Remarks

Dependent on DbContextOptions`1 being injected.

Registration of that dependency in the DI container would by typically done by calling AddDbContext``1 , or one of it's overloads.

<a name='T-Semantica-Storage-EntityFramework-DbContexts-DbContextFactory`1'></a>

DbContextFactory`1 type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Inherit from parent.

Generic Types
Name Description
TDbContext Type inheriting from DbContext. Must have a constructor with a single argument of type
DbContextOptions`1.
Remarks

Dependent on DbContextOptions`1 being injected.

Registration of that dependency in the DI container would by typically done by calling AddDbContext``1 , or one of it's overloads.

<a name='T-Semantica-Storage-EntityFramework-DbContexts-DbContextProvider'></a>

DbContextProvider type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Inherit from parent.

Summary

Dependent on IDbContextFactory being injected.

Registration of that dependency in the DI container can be done by using one of the methods from ModuleExtensions

<a name='T-Semantica-Storage-EntityFramework-DbContexts-IDbContextFactory'></a>

IDbContextFactory type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Used to create instances of DbContext.

<a name='M-Semantica-Storage-EntityFramework-DbContexts-IDbContextFactory-CreateDbContext'></a>

CreateDbContext() method

Summary

Creates the appropriate DbContext.

Returns

The application's DbContext.

Parameters

This method has no parameters.

<a name='T-Semantica-Storage-EntityFramework-DbContexts-IDbContextFactory`1'></a>

IDbContextFactory`1 type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Used to create instances of TDbContext.

<a name='M-Semantica-Storage-EntityFramework-DbContexts-IDbContextFactory`1-CreateAppDbContext'></a>

CreateAppDbContext() method

Summary

Creates the appropriate application specific DbContext.

Returns

A new instance of the application's TDbContext.

Parameters

This method has no parameters.

<a name='T-Semantica-Storage-EntityFramework-DbContexts-IDbContextProvider'></a>

IDbContextProvider type

Namespace

Semantica.Storage.EntityFramework.DbContexts

Summary

Allows for easy injection of a DbContext instance into any class. Typically used for DataStore implementations. This interface has a standard implementation within this namespace that can be registered using this packages Module. The implementation depends on IDbContextFactory also having an implementation of

<a name='T-Semantica-Storage-EntityFramework-DataStores-Inclusion`2'></a>

Inclusion`2 type

Namespace

Semantica.Storage.EntityFramework.DataStores

<a name='M-Semantica-Storage-EntityFramework-DataStores-Inclusion2-#ctor-Semantica-Storage-EntityFramework-DataStores-InclusionPrototype{0,1},Semantica-Storage-IInclusion{0}-'></a>

#ctor(inclusionPrototype,previousInclusion) constructor

Parameters
Name Type Description
inclusionPrototype Semantica.Storage.EntityFramework.DataStores.InclusionPrototype{`0,`1}
previousInclusion Semantica.Storage.IInclusion{`0}

<a name='F-Semantica-Storage-EntityFramework-DataStores-Inclusion`2-_Storables'></a>

_Storables constants

Summary

storables worden alleen opgeslagen in de eerste/diepste inclusion. Een inclusion heeft dus nooit een List van storables én een PreviousInclusion.

<a name='M-Semantica-Storage-EntityFramework-DataStores-Inclusion`2-Dispose'></a>

Dispose() method

Summary

Bij de dispose van de inclusion wordt in alle geregistreerde storage models de navigation property van de inclusion weer op null gezet. Dat betekent niet dat de verwijzing naar dat entity wordt verwijdert, maar wel dat er geen onbedoelde inserts worden gedaan bij een update op de entity.

Parameters

This method has no parameters.

<a name='T-Semantica-Storage-EntityFramework-Module'></a>

Module type

Namespace

Semantica.Storage.EntityFramework

Summary

Module that registers implementations of:

The module is dependent on implementations in the . assembly.

<a name='T-Semantica-Storage-EntityFramework-ModuleExtensions'></a>

ModuleExtensions type

Namespace

Semantica.Storage.EntityFramework

<a name='M-Semantica-Storage-EntityFramework-ModuleExtensions-RegisterDbContextFactory``1-Microsoft-Extensions-DependencyInjection-IServiceCollection-'></a>

RegisterDbContextFactory``1(serviceCollection) method

Summary

Registers the DbContextFactory`1 using the provided TDbContext as implementation for both the generic and base type IDbContextFactory.

Parameters
Name Type Description
serviceCollection Microsoft.Extensions.DependencyInjection.IServiceCollection Container/ServiceCollection to add the registrations to.
Generic Types
Name Description
TDbContext Implmentation of DbContext to register.
Remarks

Registration is done with ScopedServiceLifetime.

The DbContextFactory implementation is dependent on DbContextOptions`1 being registered. Registration of that dependency in the DI container would by typically done by calling AddDbContext``1 , or one of it's overloads.

<a name='M-Semantica-Storage-EntityFramework-ModuleExtensions-RegisterDefaultDbContextFactory-Microsoft-Extensions-DependencyInjection-IServiceCollection-'></a>

RegisterDefaultDbContextFactory(serviceCollection) method

Summary

Registers the untyped DbContextFactory as implementation for the base type IDbContextFactory.

Parameters
Name Type Description
serviceCollection Microsoft.Extensions.DependencyInjection.IServiceCollection Container/ServiceCollection to add the registrations to.
Remarks

Registration is done with ScopedServiceLifetime.

The DbContextFactory implementation is dependent on DbContextOptions`1 being registered. Registration of that dependency in the DI container would by typically done by calling AddDbContext``1 , or one of it's overloads.

<a name='T-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions'></a>

PropertyBuilderExtensions type

Namespace

Semantica.Storage.EntityFramework.Config

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-HasOwnedColumnName1-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{0},System-String,System-String-'></a>

HasOwnedColumnName``1() method

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters

This method has no parameters.

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-HasOwnedColumnName3-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{0},System-Linq-Expressions-Expression{System-Func{2,1}},System-String-'></a>

HasOwnedColumnName``3() method

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters

This method has no parameters.

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-HasPrecision-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{System-Nullable{System-Decimal}},System-Int32,System-Int32-'></a>

HasPrecision() method

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters

This method has no parameters.

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-IsCharEnum-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{System-String},System-Boolean-'></a>

IsCharEnum(unicode) method

Summary

Configures the column as a nchar(1) or char(1) column, so it can store a single unicode or ascii character. An enum type that is defined as a ushort can be assigned char values. Use CharEnumConverter to convert between enum values to string values.

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters
Name Type Description
unicode Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder{System.String} Optional. If true, the column supports unicode, otherwise only ASCII.
Remarks

If you want to use different cased characters for different enum values, make sure either the database does case sensitive string comparison, or add appropriate .

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-IsCharEnumSet-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{System-String},System-Int32,System-Boolean-'></a>

IsCharEnumSet(maxValues,unicode) method

Summary

Configures the column as a nchar() or char() column, so it can store a number of unicode or ascii character. An enum type that is defined as a ushort can be assigned char values. Use CharEnumConverter to convert between enum values to string values.

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters
Name Type Description
maxValues Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder{System.String} The maximum amount of enum values that can be stored in the column.
unicode System.Int32 Optional. If true, the column supports unicode, otherwise only ASCII.

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-IsDateOnly-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{System-DateTime}-'></a>

IsDateOnly() method

Summary

Configureert een DateTime property als een date-only veld. Voor gebruik in FluentAPI configuratie.

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters

This method has no parameters.

<a name='M-Semantica-Storage-EntityFramework-Config-PropertyBuilderExtensions-IsDateOnly-Microsoft-EntityFrameworkCore-Metadata-Builders-PropertyBuilder{System-Nullable{System-DateTime}}-'></a>

IsDateOnly() method

Summary

Configureert een DateTime property als een date-only veld. Voor gebruik in FluentAPI configuratie.

Returns

The same builder instance so that multiple configuration calls can be chained.

Parameters

This method has no parameters.

<a name='T-Semantica-Storage-EntityFramework-QueryableExtensions'></a>

QueryableExtensions type

Namespace

Semantica.Storage.EntityFramework

<a name='M-Semantica-Storage-EntityFramework-QueryableExtensions-ToReadOnlyListAsync1-System-Linq-IQueryable{0},System-Threading-CancellationToken-'></a>

ToReadOnlyListAsync``1(source,cancellationToken) method

Summary

Asynchronously creates a List`1 from an IQueryable`1 by enumerating it asynchronously, and casting it to a IReadOnlyList`1.

Returns

A task that represents the asynchronous operation. The task result contains a IReadOnlyList`1 that contains elements from the input sequence.

Parameters
Name Type Description
source System.Linq.IQueryable{``0} An IQueryable`1 to create a list from.
cancellationToken System.Threading.CancellationToken A CancellationToken to observe while waiting for the task to complete.
Generic Types
Name Description
TSource The type of the elements of source.
Exceptions
Name Description
System.ArgumentNullException source is null.
System.OperationCanceledException If the CancellationToken is canceled.
Remarks

Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context. See for more information.

See for more information.

Product 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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Semantica.Lib.Storage.EntityFramework:

Package Downloads
Semantica.Lib.Storage.EntityFramework.SimpleInjector

Package Description

Semantica.Lib.Storage.StoredProcedures

Provides abstractions and implementations for calling stored procedures.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.1.0-beta 83 5/30/2025
8.0.7-beta 88 9/6/2024
8.0.6-beta 686 7/10/2024
8.0.5-beta 116 7/4/2024
8.0.4-beta 82 7/2/2024
8.0.3-beta 74 6/14/2024
8.0.2-beta 140 6/4/2024
8.0.1-beta 69 6/4/2024
8.0.0-beta 77 6/4/2024
6.6.1-beta 210 4/5/2024
6.6.0-beta 247 3/5/2024
6.5.5-alpha2 90 3/4/2024
6.5.4-beta 114 2/29/2024
6.5.3-beta 535 10/5/2023
6.5.2-beta 96 10/5/2023
6.5.1-beta 154 9/29/2023
6.5.0-beta 118 9/22/2023
6.4.0-beta 417 7/11/2023
6.3.0-beta 145 6/15/2023
6.2.5-beta 201 3/14/2023
6.2.4-beta 589 10/12/2022
6.2.3-beta 270 9/1/2022
6.2.1-beta 187 8/25/2022