Class EntityFrameworkCoreRepository<TResource, TId>
- Namespace
- JsonApiDotNetCore.Repositories
- Assembly
- JsonApiDotNetCore.dll
Implements the foundational Repository layer in the JsonApiDotNetCore architecture that uses Entity Framework Core.
[PublicAPI]
public class EntityFrameworkCoreRepository<TResource, TId> : IResourceRepository<TResource, TId>, IResourceReadRepository<TResource, TId>, IResourceWriteRepository<TResource, TId>, IRepositorySupportsTransaction where TResource : class, IIdentifiable<TId>
Type Parameters
TResourceThe resource type.
TIdThe resource identifier type.
- Inheritance
-
EntityFrameworkCoreRepository<TResource, TId>
- Implements
-
IResourceRepository<TResource, TId>IResourceReadRepository<TResource, TId>IResourceWriteRepository<TResource, TId>
- Inherited Members
Constructors
EntityFrameworkCoreRepository(ITargetedFields, IDbContextResolver, IResourceGraph, IResourceFactory, IEnumerable<IQueryConstraintProvider>, ILoggerFactory, IResourceDefinitionAccessor)
public EntityFrameworkCoreRepository(ITargetedFields targetedFields, IDbContextResolver dbContextResolver, IResourceGraph resourceGraph, IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory, IResourceDefinitionAccessor resourceDefinitionAccessor)
Parameters
targetedFieldsITargetedFieldsdbContextResolverIDbContextResolverresourceGraphIResourceGraphresourceFactoryIResourceFactoryconstraintProvidersIEnumerable<IQueryConstraintProvider>loggerFactoryILoggerFactoryresourceDefinitionAccessorIResourceDefinitionAccessor
Properties
TransactionId
Identifies the currently active transaction.
public virtual string? TransactionId { get; }
Property Value
Methods
AddToToManyRelationshipAsync(TResource?, TId, ISet<IIdentifiable>, CancellationToken)
Adds resources to a to-many relationship in the underlying data store.
public virtual Task AddToToManyRelationshipAsync(TResource? leftResource, TId leftId, ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
Parameters
leftResourceTResourceleftIdTIdrightResourceIdsISet<IIdentifiable>cancellationTokenCancellationToken
Returns
ApplyQueryLayer(QueryLayer)
protected virtual IQueryable<TResource> ApplyQueryLayer(QueryLayer queryLayer)
Parameters
queryLayerQueryLayer
Returns
- IQueryable<TResource>
AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute, object?)
protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute relationship, object? rightValue)
Parameters
relationshipRelationshipAttributerightValueobject
CountAsync(FilterExpression?, CancellationToken)
Executes a read query using the specified filter and returns the count of matching resources.
public virtual Task<int> CountAsync(FilterExpression? filter, CancellationToken cancellationToken)
Parameters
filterFilterExpressioncancellationTokenCancellationToken
Returns
CreateAsync(TResource, TResource, CancellationToken)
Creates a new resource in the underlying data store.
public virtual Task CreateAsync(TResource resourceFromRequest, TResource resourceForDatabase, CancellationToken cancellationToken)
Parameters
resourceFromRequestTResourceresourceForDatabaseTResourcecancellationTokenCancellationToken
Returns
DeleteAsync(TResource?, TId, CancellationToken)
Deletes an existing resource from the underlying data store.
public virtual Task DeleteAsync(TResource? resourceFromDatabase, TId id, CancellationToken cancellationToken)
Parameters
resourceFromDatabaseTResourceidTIdcancellationTokenCancellationToken
Returns
GetAll()
protected virtual IQueryable<TResource> GetAll()
Returns
- IQueryable<TResource>
GetAsync(QueryLayer, CancellationToken)
Executes a read query using the specified constraints and returns the collection of matching resources.
public virtual Task<IReadOnlyCollection<TResource>> GetAsync(QueryLayer queryLayer, CancellationToken cancellationToken)
Parameters
queryLayerQueryLayercancellationTokenCancellationToken
Returns
- Task<IReadOnlyCollection<TResource>>
GetForCreateAsync(Type, TId, CancellationToken)
Creates a new resource instance, in preparation for CreateAsync(TResource, TResource, CancellationToken).
public virtual Task<TResource> GetForCreateAsync(Type resourceClrType, TId id, CancellationToken cancellationToken)
Parameters
resourceClrTypeTypeidTIdcancellationTokenCancellationToken
Returns
- Task<TResource>
Remarks
This method can be overridden to assign resource-specific required relationships.
GetForUpdateAsync(QueryLayer, CancellationToken)
Retrieves a resource with all of its attributes, including the set of targeted relationships, in preparation for UpdateAsync(TResource, TResource, CancellationToken).
public virtual Task<TResource?> GetForUpdateAsync(QueryLayer queryLayer, CancellationToken cancellationToken)
Parameters
queryLayerQueryLayercancellationTokenCancellationToken
Returns
- Task<TResource>
GetTrackingBehavior()
protected virtual QueryTrackingBehavior? GetTrackingBehavior()
Returns
RemoveFromToManyRelationshipAsync(TResource, ISet<IIdentifiable>, CancellationToken)
Removes resources from a to-many relationship in the underlying data store.
public virtual Task RemoveFromToManyRelationshipAsync(TResource leftResource, ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
Parameters
leftResourceTResourcerightResourceIdsISet<IIdentifiable>cancellationTokenCancellationToken
Returns
SaveChangesAsync(CancellationToken)
protected virtual Task SaveChangesAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
SetRelationshipAsync(TResource, object?, CancellationToken)
Performs a complete replacement of the relationship in the underlying data store.
public virtual Task SetRelationshipAsync(TResource leftResource, object? rightValue, CancellationToken cancellationToken)
Parameters
leftResourceTResourcerightValueobjectcancellationTokenCancellationToken
Returns
UpdateAsync(TResource, TResource, CancellationToken)
Updates the attributes and relationships of an existing resource in the underlying data store.
public virtual Task UpdateAsync(TResource resourceFromRequest, TResource resourceFromDatabase, CancellationToken cancellationToken)
Parameters
resourceFromRequestTResourceresourceFromDatabaseTResourcecancellationTokenCancellationToken
Returns
UpdateRelationshipAsync(RelationshipAttribute, TResource, object?, CancellationToken)
protected Task UpdateRelationshipAsync(RelationshipAttribute relationship, TResource leftResource, object? valueToAssign, CancellationToken cancellationToken)
Parameters
relationshipRelationshipAttributeleftResourceTResourcevalueToAssignobjectcancellationTokenCancellationToken