UEntity.EntityFrameworkCore.PostgreSQL 9.0.0-preview.3.1

This is a prerelease version of UEntity.EntityFrameworkCore.PostgreSQL.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package UEntity.EntityFrameworkCore.PostgreSQL --version 9.0.0-preview.3.1                
NuGet\Install-Package UEntity.EntityFrameworkCore.PostgreSQL -Version 9.0.0-preview.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UEntity.EntityFrameworkCore.PostgreSQL" Version="9.0.0-preview.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UEntity.EntityFrameworkCore.PostgreSQL --version 9.0.0-preview.3.1                
#r "nuget: UEntity.EntityFrameworkCore.PostgreSQL, 9.0.0-preview.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UEntity.EntityFrameworkCore.PostgreSQL as a Cake Addin
#addin nuget:?package=UEntity.EntityFrameworkCore.PostgreSQL&version=9.0.0-preview.3.1&prerelease

// Install UEntity.EntityFrameworkCore.PostgreSQL as a Cake Tool
#tool nuget:?package=UEntity.EntityFrameworkCore.PostgreSQL&version=9.0.0-preview.3.1&prerelease                

This IEntityRepository interface represents a generic entity repository interface. This interface defines standard CRUD (Create, Read, Update, Delete) operations for interacting with entities in a database table and provides various methods for query operations.

Features:

Various Query Methods: Various query methods such as Get, GetAll, GetArray, etc. support operations such as filtering, sorting, tracking.

Asynchronous Operations: Methods ending with async can run asynchronously so that the thread is not blocked.

Query Results: Query methods return entity objects, usually of type T, or specific properties of those entity objects.

Dynamic Filtering: Filtering operations can be configured dynamically using LINQ expressions. Sorting and Tracking: Some methods take parameters to configure sorting or tracking behaviour.

Batch Operations: Batch operations such as AddRange, UpdateRange, DeleteRange can be used to manipulate entity objects in a collection.

This interface is often used to abstract the data access operations of entity classes and reduce dependencies. It allows database operations to be independently testable and improves the overall performance and readability of the code.

Examples


// Definition
public class Product : IEntity
{
    public int Id { get; set; }
    public string Name { get; set; } = null!;
}

public interface IProductDal : IEntityRepository<Product>
{

}

public class ProductDal(TestDbContext context) : EfEntityRepositoryBase<Product, TestDbContext>(context), IProductDal
{

}

// Usage
public class ProductService(IProductDal productDal)
{
    // Counting the number of entities that match the specified filter
    int count = productDal.Count(e => e.IsActive);

    // Getting a single entity that matches the specified filter
    var entity = productDal.Get(e => e.Id == 1);

    // Getting all entities
    var allEntities = productDal.GetAll();

    // Get select
    var model = productDal.Get<Model>(x => x.Id == 5, x => new Model {
        Name = x.Name
    });

    // Get selects
    var models = productDal.GetSelectList<Model>(x => new Model {
        Name = x.Name
    }, x => x.Name.Contains("11"));

    // Getting an array of entities that match the specified filter and sorting them
    var sortedEntities = productDal.GetArray(filter: e => e.IsActive, sort: new EntitySortModel<MyEntity> { sort = x => x.Name });

    // Getting a paginated list of entities
    var paginatedList = productDal.GetListPaginate(page: 1, size: 10, filter: e => e.IsActive);

    // Adding a new entity to the repository
    var newEntity = new MyEntity { Name = "New Entity" };
    productDal.Add(newEntity);

    // Updating an existing entity in the repository
    var existingEntity = productDal.Get(e => e.Id == 1);
    existingEntity.Name = "Updated Entity";
    productDal.Update(existingEntity);

    // Deleting an entity from the repository
    var entityToDelete = productDal.Get(e => e.Id == 2);
    productDal.Delete(entityToDelete);

    // Asynchronously counting the number of entities that match the specified filter
    var countAsync = await productDal.CountAsync(e => e.IsActive);

    // Asynchronously getting a single entity that matches the specified filter
    var entityAsync = await productDal.GetAsync(e => e.Id == 1);

    // Asynchronously getting all entities
    var allEntitiesAsync = await productDal.GetAllAsync();

    // Asynchronously getting an array of entities that match the specified filter and sorting them
    var sortedEntitiesAsync = await productDal.GetArrayAsync(filter: e => e.IsActive, sort: new EntitySortModel<MyEntity> { sort = x => x.Name });

    // Asynchronously getting a paginated list of entities
    var paginatedListAsync = await productDal.GetListPaginateAsync(page: 1, size: 10, filter: e => e.IsActive);

    // Asynchronously adding a new entity to the repository
    var newEntityAsync = new MyEntity { Name = "New Entity" };
    await productDal.AddAsync(newEntityAsync);

    // Asynchronously updating an existing entity in the repository
    var existingEntityAsync = await productDal.GetAsync(e => e.Id == 1);
    existingEntityAsync.Name = "Updated Entity";
    await productDal.UpdateAsync(existingEntityAsync);

    // Asynchronously deleting an entity from the repository
    var entityToDeleteAsync = await productDal.GetAsync(e => e.Id == 2);
    await productDal.DeleteAsync(entityToDeleteAsync);

    // Asynchronously executing a delete operation on entities that match the specified filter
    await productDal.ExecuteDeleteAsync(x => x.Name.Contains("55"));

    // Asynchronously executing an update operation on entities that match the specified filter
    await agentDal.ExecuteUpdateAsync(x => x.SetProperty(p => p.Name, p => "Updated"), x => x.Id == 11);
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0-rc.2 73 10/24/2024
9.0.0-rc.1 145 9/27/2024
9.0.0-preview.3.1 55 6/12/2024
9.0.0-preview.3 59 6/9/2024
8.0.4.8 203 6/16/2024
8.0.4.7 61 6/16/2024
8.0.4.6 60 6/12/2024
8.0.4.5 109 6/9/2024
8.0.4.4 103 6/8/2024
8.0.4.3 115 6/5/2024
8.0.4.2 143 5/25/2024
8.0.4.1 105 5/25/2024
8.0.4 106 5/20/2024