RCommon
HomeGitHub
  • Introduction
  • Common Scenarios
  • Getting Started
    • Running Examples
    • Roadmap
    • Releases
      • 1.0.1.75
      • 1.0.2.0
      • 2.0.0
      • 2.1.0
  • Topics
    • Fundamentals
      • Configuration
      • Logging
      • GUID Generation
      • Time and Date
      • Emailing
        • SMTP Email
        • SendGrid Email API
      • Data Transfer Objects
        • Pagination
      • Security
        • Current User
        • Claims
      • Events
        • Transactional Events
        • Synchronous Events
        • Asynchronous Events
        • Producers
        • Subscribers
      • Validation
        • Fluent Validation
      • Caching
        • Dynamically Compiled Expressions
        • Persistence Caching
        • Caching Services
        • Redis & Valkey
        • Memory Cache
      • Serialization
        • JSON.NET
        • System.Text.Json
    • Patterns
      • Specification
      • Mediator
        • MediatR
          • Validator Behavior
          • Unit of Work Behavior
          • Logging Behavior
      • CQRS
        • Commands
        • Queries
      • Persistence
        • Repository
          • Entity Framework Core
          • Dapper
          • Linq2Db
        • Transactions
          • Unit of Work
      • Event Bus
        • In Memory
        • MediatR
        • Wolverine
      • Message Bus
        • MassTransit
        • Wolverine
    • Architecture
      • Overview
      • Microservices
      • Clean Architecture
      • Event Driven Architecture
  • Examples
    • Clean Architecture
    • CQRS
    • Mediator: MediatR
    • Event Handling: In Memory
    • Event Handling: MediatR
    • Event Handling: MassTransit
    • Event Handling: Wolverine
    • Validation: Fluent Validation
Powered by GitBook
On this page
  • Persistence Features
  • Supported Object Relational Mappers (ORMs)
  1. Topics
  2. Patterns
  3. Persistence

Repository

The ubiquitous repository pattern as it is implemented by RCommon.

PreviousPersistenceNextEntity Framework Core

Last updated 10 months ago

There has been much said about the repository pattern over the years. Perhaps the most influential .

Through the repository pattern, we are able to implement a variety of useful techniques such as eager loading, pagination, and .

public class DeleteLeaveRequestCommandHandler : IRequestHandler<DeleteLeaveRequestCommand>
{
    private readonly IFullFeaturedRepository<LeaveRequest> _leaveRequestRepository;

    public DeleteLeaveRequestCommandHandler(IFullFeaturedRepository<LeaveRequest> leaveRequestRepository)
    {
        this._leaveRequestRepository = leaveRequestRepository;
        this._leaveRequestRepository.DataStoreName = "LeaveManagement";
    }

    public async Task<Unit> Handle(DeleteLeaveRequestCommand request, CancellationToken cancellationToken)
    {
        var leaveRequest = await _leaveRequestRepository.FindAsync(request.Id);

        if (leaveRequest == null)
            throw new NotFoundException(nameof(LeaveRequest), request.Id);

        await _leaveRequestRepository.DeleteAsync(leaveRequest);
        return Unit.Value;
    }
}

Persistence Features

RCommon provides a variety of strategies for persistence. Our opinion is that object relational mappers (ORM's) can be divided into three categories with distinct but not exclusive feature sets. Categorically, these features have pros and cons but in general, you find that the more features an ORM has, the easier it is to do certain things programmatically which ultimately saves you time. However, those extra features often cost you performance.

Ultimately you are choosing an ORM based on your architectural AND operational needs. RCommon has implemented three of the most widely adopted ORMs available today - one from each category which ultimately gives you the flexibility you need to adapt as your needs change which frees you from much of the heartbreak of "Day-Zero" decisions.

Feature
Graph Mapper
Linq Mapper
SQL Mapper

Implements IQueryable

Eager Loading

Lazy Loading

Graph Persistence (nested entities)

Change Tracking

ACID Transactions

Custom SQL/Queries

Fluent Entity Mapping

Persistence Events

Unit of Work Support

Supported Object Relational Mappers (ORMs)

ORM
Graph Mapper
Linq Mapper
SQL Mapper

Entity Framework Core

Mongo DB Client (soon)

Linq2Db

Dapper

advocate for the repository pattern is Martin Fowler
unit of work (UoW)
✅
✅
❌
✅
✅
❌
✅
❌
❌
✅
❌
❌
✅
❌
❌
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
✅
❌
❌
✅
✅
❌
❌
✅