RuculaX.EntityFramework 1.3.0

dotnet add package RuculaX.EntityFramework --version 1.3.0
                    
NuGet\Install-Package RuculaX.EntityFramework -Version 1.3.0
                    
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="RuculaX.EntityFramework" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RuculaX.EntityFramework" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="RuculaX.EntityFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RuculaX.EntityFramework --version 1.3.0
                    
#r "nuget: RuculaX.EntityFramework, 1.3.0"
                    
#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.
#:package RuculaX.EntityFramework@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RuculaX.EntityFramework&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=RuculaX.EntityFramework&version=1.3.0
                    
Install as a Cake Tool

<p align="center"> <img src="../../Ruculax.png" style="width:200px"> <h1 align="center"> Ruculax Entity Framework</h1> </p>

<p align="center"> <a href="https://circleci.com/gh/angular/workflows/angular/tree/main"> <img src="https://img.shields.io/badge/license-MIT-blue" alt="License" /> </a>  <a href="https://www.nuget.org/packages/RuculaX.EntityFramework/"> <img src="https://img.shields.io/nuget/v/RuculaX.EntityFramework" alt="Version RuculaX Entity Framewrok" /> </a>  <a href="https://github.com/reginaldo-marinho/rucula-x/graphs/contributors"> <img src="https://img.shields.io/github/contributors/reginaldo-marinho/rucula-x" alt="Discord conversation" /> </a> <a href="https://github.com/reginaldo-marinho/rucula-x/commits/main"> <img src="https://img.shields.io/github/last-commit/reginaldo-marinho/rucula-x" alt="Discord conversation" /> </a>

<a href="https://www.nuget.org/packages/RuculaX.EntityFramework/"> <img src="https://img.shields.io/nuget/dt/RuculaX.EntityFramework" alt="Discord conversation" /> </a> </p>

Criando Repositório

Se você deseja criar repositórios consistentes, com muita pouca linha de codigo, esse projeto é para você.

Aqui substituimos dezenas de interfaces por uma unica classe base, o que garante facilidade na suas utilização!

// Simplesmente assim
public class RepositorySale : RepositoryCrudBaseAsync<Sale, string>
{
    public RepositorySale(DbContext context) : base(context)
    {
    }
}

Garanta que seus Modelos sejam Entidades

As Entidades simplesmente representam a Primary Key do Modelo, o que pode ser simples ou composta.

Entity

Entity<T> representa uma Entidade com uma propriedade Id do tipo T, use esse tipo quando você sabe que sua representação SQL terá somente um campo Primary key.

public class Sale : Entity<string>
{
    public string? Seller { get; set; }    
    public string? Buyer { get; set; }    
}
-- Representação SQL
CREATE TABLE Sale (
    Id NVARCHAR(50) PRIMARY KEY,
    Seller NVARCHAR(255) NULL,
    Buyer NVARCHAR(255) NULL
);
ICustomEntity

ICustomEntity é usado quando queremos representar uma Primary Key composta. Essa interface é usada juntamente com o Entity<T>.

public class SaleDetailsEntity : Entity<string>, ICustomEntity 
{
    public string CodeItem { get; set; } = "";   
}

Note que ainda estamos trabalhando com a Primary Key

Agora vamos criar nosso Modelo

public class SaleDetails : SaleDetailsEntity
{
    public string? Description { get; set; }
    public decimal? Price { get; set; }
}
-- Representação SQL
CREATE TABLE SaleDetails (
    Id NVARCHAR(50) NOT NULL,
    CodeItem NVARCHAR(50) NOT NULL,
    Description NVARCHAR(255) NULL,
    Price DECIMAL(18, 2) NULL,
    PRIMARY KEY (Id, CodeItem)
);

Com esses dois tipos de configuração de Entidade nos nossos modelos, o Ruculax Entity Framework será capaz de prestar suporte à operações CRUD.

Herde da Classe base RepositoryCrudBaseAsync

As operações CRUD já existe, o que resta agora é você fazer bom uso da herança, veja como é simples.

public class RepositorySale : RepositoryCrudBaseAsync<SaleDetails, string>
{
    public RepositorySale(DbContext context) : base(context)
    {
    }
}

As Operações

InsertAsync
    var sale = new Sale { Id = "324909340", Seller = "reginaldo-marinho", Buyer = "rucula-js" };
    await repositorySale.InsertAsync(sale);
GetAsync

Informe somente as propriedades que representam a Primary Key

    var sale = await repositorySale.GetAsync(new Sale { Id = "324909340"});
AlterAsync

Antes de trabalharmos com AlterAsync, precisamos conhecer a interface IAlterMap<T>, com ela, você tem segurança para alterar somente o que você deseja.

public class AlterSale : IAlterMap<Sale>
{
    private AlterSaleDto SaleDto;

    puclic AlterSale(AlterSaleDto saleDto){
        SaleDto = saleDto;
    }

    public Sale Map(Sale entity)
    {
        entity.Seller = saleDto.Seller;
        entity.Buyer = saleDto.Buyer;
        return entity;
    }
}
public class SaleAlterBuyer : IAlterMap<Sale>
{

    private string Buyer;

    puclic SaleAlterBuyer(string buyer){
        Buyer = buyer;
    }

    public Sale Map(Sale entity)
    {
        entity.Seller = Buyer;
        return entity;
    }
}

Aviso: Não tente criar outra entidade e retorna-la, o ruculax irá checar seu hash o que gerará exceção caso seja diferente.

    await repositorySale.AlterAsync(new Sale { Id = "324909340"}, new AlterSale());

Observe que Sale contém somente a propriedade que representa a Primary Key, isso porque internamente será feita uma leitura e retornado o registro para IAlterMap<T>

DeleteAsync

Informe somente as propriedades que representam a Primary Key

    var sale = new Sale { Id = "324909340"}
    await repositorySale.DeleteAsync(sale);

Trabalhando com a Unidade Lógica de Trabalho

UnitOfWorkAsync

UnitOfWorkAsync é uma classe que por padrão recebe um dbContext via construtor e posteriormente fornece os métodos de transação para seus clientes.

Para que tudo faça sentido, atente-se ao ciclo de vida do contexto, que por padrão é scoped.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
1.3.0 154 12/13/2025
1.2.0 352 6/10/2025
1.1.11 220 10/10/2024
1.1.9 167 9/21/2024
1.1.8 180 9/21/2024
1.1.7 174 9/19/2024
1.1.6 170 9/19/2024
1.1.5 187 9/17/2024
1.1.4 194 9/17/2024
1.1.3 182 7/18/2024
1.1.2 165 7/15/2024
1.0.1 179 6/27/2024
1.0.0 184 6/25/2024