Deveel Repository
Deveel
  • Why Another Repository Pattern Library?
  • The Repository Pattern
  • Getting Started
  • Customize the Repository
  • Multi-Tenancy of Data Sources
  • User Entities
  • Repository Implementations
    • In-Memory Repositories
    • Entity Framework Core Repositories
    • MongoDB Repositories
  • The Entity Manager
    • Caching Entities
Powered by GitBook
On this page
Edit on GitHub
  1. Repository Implementations

Entity Framework Core Repositories

PreviousIn-Memory RepositoriesNextMongoDB Repositories

Last updated 1 year ago

Feature
Status
Notes

Base Repository

Filterable

Queryable

Native EF Core queryable extensions

Pageable

Multi-tenant

Uses Finbuckle Multi-Tenant

The Deveel Repository framework provides an implementation of the repository pattern that uses the , and allows to access a wide range of relational databases.

The EntityRepository<TEntity> class is an implementation of the repository pattern that wraps around an instance of DbContext and provides the basic operations to query and manipulate the data.

To start using instances of the EntityRepository<TEntity> class, you need first to register a DbContext instance in the dependency injection container, that will be used to access the database, using one of the extensions methods of the IServiceCollection interface: you don't receive any special provisioning from the library, and you can use the standard methods provided by the Entity Framework Core itself.

The registration of the repository in the dependency injection container is the same provided by the kernel library, and is the following:

services.AddRepository<EntityRepository<MyEntity>>();
services.AddRepository<MyEntityRepository>();

or using the shortcut method, that will register the default implementation of the repository:

services.AddEntityRepository<MyEntity>();

Remember that you still need to register the DbContext in the dependency injection container, and that the EntityRepository<TEntity> class requires a constructor that accepts an instance of DbContext as parameter.

The simplest use case for this is the following set of calls:

services.AddDbContext<MyDbContext>(options => options.UseSqlServer("<connection_string>"));
services.AddRepository<EntityRepository<MyEntity>>();

The library provides a shortcut method to register the DbContext in multi-tenant applications, using the ITenantInfo interface provided by the framework.

For example:

services.AddDbContextForTenant<MyDbContext, TenantInfo>((tenant, options) => options.UseSqlServer(tenant.ConnectionString));

Filtering Data

The EntityRepository<TEntity> implements both the IQueryableRepository<TEntity> and the IFilterableRepository<TEntity> interfaces, and allows to query the data only through the ExpressionFilter<TEntity> class or through lambda expressions of type Expression<Func<TEntity, bool>>.

For example, to retrieve all the entities of type MyEntity that have a property Name equal to "John":

var entities = await repository.FindAllAsync(new ExpressionFilter<MyEntity>(x => x.Name == "John"));

or event simpler, using the lambda expression:

var entities = await repository.FindAllAsync(x => x.Name == "John");

Note: Please, refer to the official documentation by Microsoft for more information on how to configure the DbContext in your application, and the documentation of the framework for more information on how to configure the multi-tenant support and its support for .

Entity Framework Core
Finbuckle.MultiTenant
Finbuckle.MultiTenant
Entity Framework Core
✅
✅
✅
✅
✅