Show / Hide Table of Contents

Class MongoDBRepository<T>

Abstract base class for MongoDB repositories. GlitchedPolygons.RepositoryPattern.IRepository<T1, T2>

Inheritance
System.Object
MongoDBRepository<T>
Implements
GlitchedPolygons.RepositoryPattern.IRepository<T, MongoDB.Bson.ObjectId>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: GlitchedPolygons.RepositoryPattern.MongoDB
Assembly: GlitchedPolygons.RepositoryPattern.MongoDB.dll
Syntax
public abstract class MongoDBRepository<T> : IRepository<T, ObjectId> where T : IEntity<ObjectId>
Type Parameters
Name Description
T

The type of entity that this repository will store.

Constructors

| Improve this Doc View Source

MongoDBRepository(IMongoDatabase, String)

Creates a new MongoDB repository.

Declaration
protected MongoDBRepository(IMongoDatabase db, string collectionName = null)
Parameters
Type Name Description
MongoDB.Driver.IMongoDatabase db

The Mongo database of which you want to create a repository.

System.String collectionName

Optional custom name for the underlying MongoDB collection. If left out, the entity's name is used.

Fields

| Improve this Doc View Source

collection

The underlying MongoDB collection.

Declaration
protected readonly IMongoCollection<T> collection
Field Value
Type Description
MongoDB.Driver.IMongoCollection<T>
| Improve this Doc View Source

db

The underlying Mongo database.

Declaration
protected readonly IMongoDatabase db
Field Value
Type Description
MongoDB.Driver.IMongoDatabase

Properties

| Improve this Doc View Source

CollectionName

The name of the repository's underlying MongoDB collection.

Declaration
public string CollectionName { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

Item[ObjectId]

Synchronously gets an entity by its unique identifier.

Declaration
public T this[ObjectId id] { get; }
Parameters
Type Name Description
MongoDB.Bson.ObjectId id

The entity's unique identifier.

Property Value
Type Description
T

The found entity; null if the entity couldn't be found.

Methods

| Improve this Doc View Source

Add(T)

Adds the specified entity to the data repository.

Declaration
public Task<bool> Add(T entity)
Parameters
Type Name Description
T 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<T>)

Adds multiple entities at once.

Declaration
public Task<bool> AddRange(IEnumerable<T> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> 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<T, Boolean>>)

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

Declaration
public Task<IEnumerable<T>> Find(Expression<Func<T, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T, 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<T>>

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

| Improve this Doc View Source

Get(ObjectId)

Gets an entity by its unique identifier.

Declaration
public Task<T> Get(ObjectId id)
Parameters
Type Name Description
MongoDB.Bson.ObjectId id

The entity's unique identifier.

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

The first found GlitchedPolygons.RepositoryPattern.IEntity`1; null if nothing was found.

| Improve this Doc View Source

GetAll()

Gets all entities from the repository.

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

All entities inside the repo.

| Improve this Doc View Source

Remove(T)

Removes the specified entity.

Declaration
public Task<bool> Remove(T entity)
Parameters
Type Name Description
T 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(ObjectId)

Removes the specified entity.

Declaration
public Task<bool> Remove(ObjectId id)
Parameters
Type Name Description
MongoDB.Bson.ObjectId 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
public 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>> ).

Exceptions
Type Condition
System.NotImplementedException
| Improve this Doc View Source

RemoveRange(IEnumerable<T>)

Removes the range of entities from the repository.

Declaration
public Task<bool> RemoveRange(IEnumerable<T> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> 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<ObjectId>)

Removes the range of entities from the repository.

Declaration
public Task<bool> RemoveRange(IEnumerable<ObjectId> ids)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<MongoDB.Bson.ObjectId> 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<T, Boolean>>)

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

Declaration
public Task<bool> RemoveRange(Expression<Func<T, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T, 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<T, 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
public Task<T> SingleOrDefault(Expression<Func<T, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T, System.Boolean>> predicate

The search predicate.

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

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

| Improve this Doc View Source

Update(T)

Updates the specified entity.

Declaration
public abstract Task<bool> Update(T entity)
Parameters
Type Name Description
T entity

The entity to update.

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

Whether the entity could be updated successfully or not.

Implements

GlitchedPolygons.RepositoryPattern.IRepository<T1, T2>
  • Improve this Doc
  • View Source
Back to top Generated by DocFX