Show / Hide Table of Contents

Interface IRepository<T1, T2>

Generic repository base interface for holding any type of uniquely identifiable IEntity<T>. Typically used for database access routines.

Namespace: GlitchedPolygons.RepositoryPattern
Assembly: GlitchedPolygons.RepositoryPattern.dll
Syntax
public interface IRepository<T1, in T2>
    where T1 : IEntity<T2>
Type Parameters
Name Description
T1

The type of entity that the repository is going to store.

T2

The type of unique id that the repository's entities will have (e.g. guid string, int, etc...).

Properties

| Improve this Doc View Source

Item[T2]

Gets the entity of type T1 with the specified unique identifier (synchronously).

Declaration
T1 this[T2 id] { get; }
Parameters
Type Name Description
T2 id

The entity's unique identifier.

Property Value
Type Description
T1

The first found entity; null if nothing was found.

Methods

| Improve this Doc View Source

Add(T1)

Adds the specified entity to the data repository.

Declaration
Task<bool> Add(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to add.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be added successfully or not.

| Improve this Doc View Source

AddRange(IEnumerable<T1>)

Adds multiple entities at once.

Declaration
Task<bool> AddRange(IEnumerable<T1> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T1> entities

The entities to add.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were added successfully or not.

| Improve this Doc View Source

Find(Expression<Func<T1, Boolean>>)

Finds all entities according to the specified predicate System.Linq.Expressions.Expression.

Declaration
Task<IEnumerable<T1>> Find(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The search predicate (all entities that match the provided conditions will be added to the query's result).

Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<T1>>

The found entities (System.Collections.Generic.IEnumerable<T>).

| Improve this Doc View Source

Get(T2)

Gets an entity by its unique identifier.

Declaration
Task<T1> Get(T2 id)
Parameters
Type Name Description
T2 id

The entity's unique identifier.

Returns
Type Description
System.Threading.Tasks.Task<T1>

The first found IEntity<T>; null if nothing was found.

| Improve this Doc View Source

GetAll()

Gets all entities from the repository.

Declaration
Task<IEnumerable<T1>> GetAll()
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<T1>>

All entities inside the repo.

| Improve this Doc View Source

Remove(T1)

Removes the specified entity.

Declaration
Task<bool> Remove(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be removed successfully or not.

| Improve this Doc View Source

Remove(T2)

Removes the specified entity.

Declaration
Task<bool> Remove(T2 id)
Parameters
Type Name Description
T2 id

The unique id of the entity to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be removed successfully or not.

| Improve this Doc View Source

RemoveAll()

Removes all entities at once from the repository.

Declaration
Task<bool> RemoveAll()
Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were removed successfully or not. If the repository was already empty, false is returned (because nothing was actually <<removed>> ).

| Improve this Doc View Source

RemoveRange(IEnumerable<T1>)

Removes the range of entities from the repository.

Declaration
Task<bool> RemoveRange(IEnumerable<T1> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T1> entities

The entities to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were removed successfully or not.

| Improve this Doc View Source

RemoveRange(IEnumerable<T2>)

Removes the range of entities from the repository.

Declaration
Task<bool> RemoveRange(IEnumerable<T2> ids)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T2> ids

The unique ids of the entities to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether all entities were removed successfully or not.

| Improve this Doc View Source

RemoveRange(Expression<Func<T1, Boolean>>)

Removes all entities that match the specified conditions (via the predicate System.Linq.Expressions.Expression parameter).

Declaration
Task<bool> RemoveRange(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The predicate System.Linq.Expressions.Expression that defines which entities should be removed.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were removed successfully or not.

| Improve this Doc View Source

SingleOrDefault(Expression<Func<T1, Boolean>>)

Gets a single entity from the repo according to the specified predicate condition.

If 0 or >1 entities are found, null is returned.

Declaration
Task<T1> SingleOrDefault(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The search predicate.

Returns
Type Description
System.Threading.Tasks.Task<T1>

Single found entity; null if 0 or >1 entities were found.

| Improve this Doc View Source

Update(T1)

Updates the specified entity.

Declaration
Task<bool> Update(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to update.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be updated successfully or not.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX