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
TResource
The resource type.
TId
The 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
targetedFields
ITargetedFieldsdbContextResolver
IDbContextResolverresourceGraph
IResourceGraphresourceFactory
IResourceFactoryconstraintProviders
IEnumerable<IQueryConstraintProvider>loggerFactory
ILoggerFactoryresourceDefinitionAccessor
IResourceDefinitionAccessor
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
leftResource
TResourceleftId
TIdrightResourceIds
ISet<IIdentifiable>cancellationToken
CancellationToken
Returns
ApplyQueryLayer(QueryLayer)
protected virtual IQueryable<TResource> ApplyQueryLayer(QueryLayer queryLayer)
Parameters
queryLayer
QueryLayer
Returns
- IQueryable<TResource>
AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute, object?)
protected void AssertIsNotClearingRequiredToOneRelationship(RelationshipAttribute relationship, object? rightValue)
Parameters
relationship
RelationshipAttributerightValue
object
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
filter
FilterExpressioncancellationToken
CancellationToken
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
resourceFromRequest
TResourceresourceForDatabase
TResourcecancellationToken
CancellationToken
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
resourceFromDatabase
TResourceid
TIdcancellationToken
CancellationToken
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
queryLayer
QueryLayercancellationToken
CancellationToken
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
resourceClrType
Typeid
TIdcancellationToken
CancellationToken
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
queryLayer
QueryLayercancellationToken
CancellationToken
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
leftResource
TResourcerightResourceIds
ISet<IIdentifiable>cancellationToken
CancellationToken
Returns
SaveChangesAsync(CancellationToken)
protected virtual Task SaveChangesAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationToken
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
leftResource
TResourcerightValue
objectcancellationToken
CancellationToken
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
resourceFromRequest
TResourceresourceFromDatabase
TResourcecancellationToken
CancellationToken
Returns
UpdateRelationshipAsync(RelationshipAttribute, TResource, object?, CancellationToken)
protected Task UpdateRelationshipAsync(RelationshipAttribute relationship, TResource leftResource, object? valueToAssign, CancellationToken cancellationToken)
Parameters
relationship
RelationshipAttributeleftResource
TResourcevalueToAssign
objectcancellationToken
CancellationToken