Owneat Technical Guide main Help

Class Repository<TType, TContext\>

Namespace: Common.Repositories
Assembly: Common.dll

Implementation of Common.Contracts.IRepository%601 with all generic methods to manipulate entities in database.

public class Repository<TType, TContext> : IRepository<TType> where TType : Entity where TContext : DbContext

Type Parameters

TType

The entity type.

TContext

The context type.

Inheritance

object ← Repository<TType, TContext\>

Implements

IRepository<TType\>

Inherited Members

object.Equals\(object?\), object.Equals\(object?, object?\), object.GetHashCode\(\), object.GetType\(\), object.MemberwiseClone\(\), object.ReferenceEquals\(object?, object?\), object.ToString\(\)

Constructors

Repository\(TContext\)

Implementation of Common.Contracts.IRepository%601 with all generic methods to manipulate entities in database.

public Repository(TContext context)

Parameters

context TContext

Fields

Context

protected readonly TContext Context

Field Value

TContext

Methods

Add\(TType\)

Method that add an entity of type T in the database.

public TType Add(TType entity)

Parameters

entity TType

Returns

TType

The added entity.

Delete\(TType\)

Method that remove an entity of type T from the database.

public void Delete(TType entity)

Parameters

entity TType

DeleteRange\(IEnumerable<TType\>\)

Method that remove all passed entities of type T from the database.

public void DeleteRange(IEnumerable<TType> entities)

Parameters

entities IEnumerable <TType\>

Exists\(Func<TType, bool\>\)

Method that check if entity of type T in the database responds to a certain predicate.

public bool Exists(Func<TType, bool> predicate)

Parameters

predicate Func <TType, bool \>

Returns

bool

True if the entities in database respond to the given predicate, false otherwise.

GetAllAsync\(\)

Method that get all entities of type T in the database.

public Task<IEnumerable<TType>> GetAllAsync()

Returns

Task < IEnumerable <TType\>\>

System.Collections.Generic.IEnumerable%601 that contains all the elements.

GetByIdAsync\(Guid\)

Method that get an entity of type T in the database by it's System.Guid.

public Task<TType?> GetByIdAsync(Guid entityId)

Parameters

entityId Guid

Returns

Task <TType?\>

Remarks

This method doesn't include related entities.

GetByIdAsyncWithConcurrency\(Guid\)

Method that get an entity of type T in the database by it's System.Guid. Remove entity tracking that was previously stored in it.

public Task<TType?> GetByIdAsyncWithConcurrency(Guid entityId)

Parameters

entityId Guid

Returns

Task <TType?\>

Remarks

This method doesn't include related entities.

Update\(TType\)

Method that update an entity of type T in the database.

public void Update(TType entity)

Parameters

entity TType

UpdateRange\(IEnumerable<TType\>\)

Method that update an entity of type T in the database.

public void UpdateRange(IEnumerable<TType> entities)

Parameters

entities IEnumerable <TType\>

Last modified: 21 May 2024